different kinds of headlines master
authorSabine Engelhardt (Becker) <frosch@atari-frosch.de>
Sun, 2 Feb 2020 04:02:51 +0000 (05:02 +0100)
committerSabine Engelhardt (Becker) <frosch@atari-frosch.de>
Sun, 2 Feb 2020 04:02:51 +0000 (05:02 +0100)
CHANGELOG
makesite.py

index ee3b253..87518e4 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,11 @@
+2020-02-02 frosch@atari-frosch.de
+
+    * makesite.py now knows the possibility to have a static headline on
+      each page plus a headline in the content part. If the static headline
+      is set, it is set in <h1> and the headline in the content part should
+      be set in <h2>.
+
+
 2019-11-16 frosch@atari-frosch.de
 
     * module randomphoto-piwigo.py: The problem still occured and is now
index 4471fb2..f7354c8 100755 (executable)
@@ -26,7 +26,12 @@ def defaulthtmlhead(contentfile, htmlhead, settings, pageconf):
     try:
         pageconf["doctype"]
     except KeyError:
-        head = head.replace("[DOCTYPE]", settings.doctype)
+        try:
+            settings.doctype
+        except AttributeError:
+            head = head.replace("[DOCTYPE]", "")
+        else:
+            head = head.replace("[DOCTYPE]", settings.doctype)
     else:
         head = head.replace("[DOCTYPE]", pageconf["doctype"])
 
@@ -59,6 +64,23 @@ def defaulthtmlhead(contentfile, htmlhead, settings, pageconf):
         head = head.replace("[DC.DESCRIPTION]", r)
 
     try:
+        pageconf["keywords"]
+    except KeyError:
+        pass
+    else:
+        r = '<meta name="keywords" content="' + pageconf["keywords"] + metaend
+        head = head.replace("[KEYWORDS]", r)
+
+    try:
+        pageconf["author"]
+    except KeyError:
+        r = '<meta name="author" content="' + settings.author + metaend
+        head = head.replace("[AUTHOR]", r)
+    else:
+        r = '<meta name="author" content="' + pageconf["author"] + metaend
+        head = head.replace("[AUTHOR]", r)
+
+    try:
         pageconf["robots"]
     except KeyError:
         r = '<meta name="robots" content="' + settings.robots + metaend
@@ -307,7 +329,7 @@ def defaultfoot(contentfile, pagefoot, generator, myurl, pageconfig, htmlfile):
 
 def createpage(filename, sitepath, targetdir, snippets):
     if not filename.endswith(".htm"):
-        logging.debug('File %s is not to be processed. Next.', filename)
+        pass
     else:
         logging.debug('Running createpage with filename %s, targetdir %s.', filename, targetdir)
         purefilename = os.path.basename(filename)
@@ -357,34 +379,43 @@ def createpage(filename, sitepath, targetdir, snippets):
             f.close()
             htmlpage += logohtml
             logging.debug('Logo file added to page.')
+            
+            stathead = False
+            try:
+                settings.headline
+            except AttributeError:
+                logging.debug('No static headline set.')
+            else:
+                logging.debug('Static headline found and added to page.')
+                htmlpage += '        <h1>' + settings.headline + '</h1>\n'
+                stathead = True
 
             contentfile = open(filename, "r")
             content = contentfile.read()
             contentfile.close()
-            if "<h1>" not in content:
+
+            if stathead == True:
+                headlinetag = "h2"
+            else:
+                headlinetag = "h1"
+
+            headlinestart = "<" + headlinetag + ">"
+            headlineend = "</" + headlinetag + ">"
+            logging.debug("headlinestart = %s", headlinestart)
+
+            if headlinestart not in content:
                 if settings.headcontent == False:
                     try:
                         pageconfig["headline"]
                     except KeyError:
-                        # headline still might be in the content section not marked
-                        # with <h1>
+                        # headline still might be in the content section
                         logging.debug("Headline not found in page.py for %s", targetfile)
-                        try:
-                            pageconfig["title"]
-                        except AttributeError:
-                            logging.warning("Title not found in page.py for %s", targetfile)
-                            htmlpage += "        <h1>" + settings.title + "</h1>\n"
-                            logging.debug('Standard headline added to page.')
-                        else:
-                            htmlpage += "        <h1>" + pageconfig["title"] + "</h1>\n"
-                            logging.debug('Title added to page as headline.')
                     else:
-                        htmlpage += "        <h1>" + pageconfig["headline"] + "</h1>\n"
+                        htmlpage += "        " + headlinestart + pageconfig["headline"] + headlineend + "\n"
                         logging.debug('Headline added to page.')
             else:
                 logging.debug('Headline was found in the content file.')
 
-
             endpageheadfile = snippets["endpagehead"]
             f = open(endpageheadfile, "r")
             endpageheadhtml = f.read()
@@ -410,17 +441,6 @@ def createpage(filename, sitepath, targetdir, snippets):
                 else:
                     menupos = "below"
 
-            '''
-            if settings.headcontent == True:
-                # this option is not tested yet!
-                contentstartfile = snippets["contentstart"]
-                f = open(contentstartfile, "r")
-                contentstarthtml = f.read()
-                f.close()
-                htmlpage += contentstarthtml
-                htmlpage += "<h1>" + pageconfig["title"] + "</h1>\n"
-            '''
-
             try:
                 settings.addtobody
             except AttributeError:
@@ -507,6 +527,7 @@ def makepagemenu(filename, snippets, pageconfig, snippetspath):
         logging.critical('No menu file for <%s>.  Stop.', filename)
         sys.exit()
 
+
 # end of functions
 
 # check arguments
@@ -574,6 +595,9 @@ except NameError:
 else:
     logfile = settings.makelogfile
 
+if os.path.exists(logfile):
+    os.remove(logfile)
+
 try:
     settings.makeloglevel
 except NameError: