From: Vladimír Vondruš Date: Thu, 12 Sep 2019 20:54:33 +0000 (+0200) Subject: Support navbar project / brand logo in all three themes. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=2b3779cd64c251d74328c0dba03d95761d3a49ca;p=blog.git Support navbar project / brand logo in all three themes. --- diff --git a/doc/documentation/doxygen.rst b/doc/documentation/doxygen.rst index 95e2c0c0..9388c3e8 100644 --- a/doc/documentation/doxygen.rst +++ b/doc/documentation/doxygen.rst @@ -264,6 +264,8 @@ Variable Description page title :ini:`PROJECT_BRIEF` If set, appended in a thinner font to :ini:`PROJECT_NAME` +:ini:`PROJECT_LOGO` URL of an image file to use as a log in the top + navbar. Default is none. :ini:`OUTPUT_DIRECTORY` Used to discover where Doxygen generates the files :ini:`XML_OUTPUT` Used to discover where Doxygen puts the diff --git a/doc/documentation/python.rst b/doc/documentation/python.rst index ad4abcc5..f539bbdd 100644 --- a/doc/documentation/python.rst +++ b/doc/documentation/python.rst @@ -138,6 +138,8 @@ Variable Description :py:`"My Python Project"` is used. :py:`PROJECT_SUBTITLE: str` Project subtitle. If set, appended in a thinner font to :py:`PROJECT_TITLE`. +:py:`PROJECT_LOGO: str` URL of an image to use as a log in the top + navbar. Default is none. :py:`MAIN_PROJECT_URL: str` If set and :py:`PROJECT_SUBTITLE` is also set, then :py:`PROJECT_TITLE` in the top navbar will link to this URL and diff --git a/documentation/doxygen.py b/documentation/doxygen.py index 0e39cccf..5257a520 100755 --- a/documentation/doxygen.py +++ b/documentation/doxygen.py @@ -3262,6 +3262,7 @@ def parse_doxyfile(state: State, doxyfile, config = None): default_config = { 'PROJECT_NAME': ['My Project'], + 'PROJECT_LOGO': [''], 'OUTPUT_DIRECTORY': [''], 'XML_OUTPUT': ['xml'], 'HTML_OUTPUT': ['html'], @@ -3387,6 +3388,7 @@ copy a link to the result using ⌘ # String values that we want for i in ['PROJECT_NAME', 'PROJECT_BRIEF', + 'PROJECT_LOGO', 'OUTPUT_DIRECTORY', 'HTML_OUTPUT', 'XML_OUTPUT', @@ -3592,7 +3594,7 @@ def run(doxyfile, *, templates=default_templates, wildcard=default_wildcard, ind f.write(b'\n') # Copy all referenced files - for i in state.images + state.doxyfile['HTML_EXTRA_STYLESHEET'] + state.doxyfile['HTML_EXTRA_FILES'] + ([state.doxyfile['M_FAVICON'][0]] if state.doxyfile['M_FAVICON'] else []) + ([] if state.doxyfile['M_SEARCH_DISABLED'] else ['search.js']): + for i in state.images + state.doxyfile['HTML_EXTRA_STYLESHEET'] + state.doxyfile['HTML_EXTRA_FILES'] + ([state.doxyfile['PROJECT_LOGO']] if state.doxyfile['PROJECT_LOGO'] else []) + ([state.doxyfile['M_FAVICON'][0]] if state.doxyfile['M_FAVICON'] else []) + ([] if state.doxyfile['M_SEARCH_DISABLED'] else ['search.js']): # Skip absolute URLs if urllib.parse.urlparse(i).netloc: continue diff --git a/documentation/python.py b/documentation/python.py index 66d65b56..a5fec0ad 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -132,6 +132,7 @@ def default_id_formatter(type: EntryType, path: List[str]) -> str: default_config = { 'PROJECT_TITLE': 'My Python Project', 'PROJECT_SUBTITLE': None, + 'PROJECT_LOGO': None, 'MAIN_PROJECT_URL': None, 'INPUT': None, 'OUTPUT': 'output', @@ -2586,7 +2587,7 @@ def run(basedir, config, *, templates=default_templates, search_add_lookahead_ba f.write(b'\n') # Copy referenced files - for i in config['STYLESHEETS'] + config['EXTRA_FILES'] + ([config['FAVICON'][0]] if config['FAVICON'] else []) + list(state.external_data) + ([] if config['SEARCH_DISABLED'] else ['search.js']): + for i in config['STYLESHEETS'] + config['EXTRA_FILES'] + ([config['PROJECT_LOGO']] if config['PROJECT_LOGO'] else []) + ([config['FAVICON'][0]] if config['FAVICON'] else []) + list(state.external_data) + ([] if config['SEARCH_DISABLED'] else ['search.js']): # Skip absolute URLs if urllib.parse.urlparse(i).netloc: continue diff --git a/documentation/templates/doxygen/base.html b/documentation/templates/doxygen/base.html index 69d77f63..5c5a371a 100644 --- a/documentation/templates/doxygen/base.html +++ b/documentation/templates/doxygen/base.html @@ -28,10 +28,10 @@
{% if M_MAIN_PROJECT_URL and PROJECT_BRIEF %} - {{ PROJECT_NAME }} | {{ PROJECT_BRIEF }} + {% if PROJECT_LOGO %}{% endif %}{{ PROJECT_NAME }} | {{ PROJECT_BRIEF }} {% else %} - {{ PROJECT_NAME }}{% if PROJECT_BRIEF %} {{ PROJECT_BRIEF }}{% endif %} + {% if PROJECT_LOGO %}{% endif %}{{ PROJECT_NAME }}{% if PROJECT_BRIEF %} {{ PROJECT_BRIEF }}{% endif %} {% endif %} {% if M_LINKS_NAVBAR1 or M_LINKS_NAVBAR2 or not M_SEARCH_DISABLED %}
diff --git a/documentation/templates/python/base.html b/documentation/templates/python/base.html index 09857cb8..11985d5a 100644 --- a/documentation/templates/python/base.html +++ b/documentation/templates/python/base.html @@ -28,10 +28,10 @@
{% if MAIN_PROJECT_URL and PROJECT_TITLE %} - {{ PROJECT_TITLE }} | {{ PROJECT_SUBTITLE }} + {% if PROJECT_LOGO %}{% endif %}{{ PROJECT_TITLE }} | {{ PROJECT_SUBTITLE }} {% else %} - {{ PROJECT_TITLE }}{% if PROJECT_SUBTITLE %} {{ PROJECT_SUBTITLE }}{% endif %} + {% if PROJECT_LOGO %}{% endif %}{{ PROJECT_TITLE }}{% if PROJECT_SUBTITLE %} {{ PROJECT_SUBTITLE }}{% endif %} {% endif %} {% if LINKS_NAVBAR1 or LINKS_NAVBAR2 or not SEARCH_DISABLED %}
diff --git a/documentation/test_doxygen/layout_navbar_project_logo/Doxyfile b/documentation/test_doxygen/layout_navbar_project_logo/Doxyfile new file mode 100644 index 00000000..c90504de --- /dev/null +++ b/documentation/test_doxygen/layout_navbar_project_logo/Doxyfile @@ -0,0 +1,10 @@ +XML_OUTPUT = +PROJECT_NAME = "Your Brand" +PROJECT_LOGO = mosra.jpg + +##! M_PAGE_FINE_PRINT = +##! M_THEME_COLOR = +##! M_FAVICON = +##! M_LINKS_NAVBAR1 = +##! M_LINKS_NAVBAR2 = +##! M_SEARCH_DISABLED = YES diff --git a/documentation/test_doxygen/layout_navbar_project_logo/index.html b/documentation/test_doxygen/layout_navbar_project_logo/index.html new file mode 100644 index 00000000..cdcf6574 --- /dev/null +++ b/documentation/test_doxygen/layout_navbar_project_logo/index.html @@ -0,0 +1,30 @@ + + + + + Your Brand + + + + + +
+
+
+
+
+

+ Your Brand +

+
+
+
+
+ + diff --git a/documentation/test_doxygen/layout_navbar_project_logo/indexpage.xml b/documentation/test_doxygen/layout_navbar_project_logo/indexpage.xml new file mode 100644 index 00000000..afdb7bfa --- /dev/null +++ b/documentation/test_doxygen/layout_navbar_project_logo/indexpage.xml @@ -0,0 +1,11 @@ + + + + index + Your Brand + + + + + + diff --git a/documentation/test_doxygen/layout_navbar_project_logo/mosra.jpg b/documentation/test_doxygen/layout_navbar_project_logo/mosra.jpg new file mode 120000 index 00000000..d474bc98 --- /dev/null +++ b/documentation/test_doxygen/layout_navbar_project_logo/mosra.jpg @@ -0,0 +1 @@ +../../../site/content/static/mosra.jpg \ No newline at end of file diff --git a/documentation/test_doxygen/layout_navbar_project_logo_main_project_url/Doxyfile b/documentation/test_doxygen/layout_navbar_project_logo_main_project_url/Doxyfile new file mode 100644 index 00000000..0bd7b951 --- /dev/null +++ b/documentation/test_doxygen/layout_navbar_project_logo_main_project_url/Doxyfile @@ -0,0 +1,12 @@ +XML_OUTPUT = +PROJECT_NAME = "Your Brand" +PROJECT_LOGO = mosra.jpg +PROJECT_BRIEF = docs + +##! M_PAGE_FINE_PRINT = +##! M_THEME_COLOR = +##! M_FAVICON = +##! M_LINKS_NAVBAR1 = +##! M_LINKS_NAVBAR2 = +##! M_SEARCH_DISABLED = YES +##! M_MAIN_PROJECT_URL = http://your.brand diff --git a/documentation/test_doxygen/layout_navbar_project_logo_main_project_url/index.html b/documentation/test_doxygen/layout_navbar_project_logo_main_project_url/index.html new file mode 100644 index 00000000..cd8cdf1d --- /dev/null +++ b/documentation/test_doxygen/layout_navbar_project_logo_main_project_url/index.html @@ -0,0 +1,32 @@ + + + + + Your Brand docs + + + + + +
+
+
+
+
+

+ Your Brand +

+
+
+
+
+ + diff --git a/documentation/test_doxygen/layout_navbar_project_logo_main_project_url/indexpage.xml b/documentation/test_doxygen/layout_navbar_project_logo_main_project_url/indexpage.xml new file mode 100644 index 00000000..afdb7bfa --- /dev/null +++ b/documentation/test_doxygen/layout_navbar_project_logo_main_project_url/indexpage.xml @@ -0,0 +1,11 @@ + + + + index + Your Brand + + + + + + diff --git a/documentation/test_doxygen/layout_navbar_project_logo_main_project_url/mosra.jpg b/documentation/test_doxygen/layout_navbar_project_logo_main_project_url/mosra.jpg new file mode 120000 index 00000000..d474bc98 --- /dev/null +++ b/documentation/test_doxygen/layout_navbar_project_logo_main_project_url/mosra.jpg @@ -0,0 +1 @@ +../../../site/content/static/mosra.jpg \ No newline at end of file diff --git a/documentation/test_doxygen/test_doxyfile.py b/documentation/test_doxygen/test_doxyfile.py index 3d8b8f0e..0a9a7adb 100644 --- a/documentation/test_doxygen/test_doxyfile.py +++ b/documentation/test_doxygen/test_doxyfile.py @@ -77,6 +77,7 @@ copy a link to the result using ⌘ 'M_THEME_COLOR': '#22272e', 'OUTPUT_DIRECTORY': '', 'PROJECT_BRIEF': 'is cool', + 'PROJECT_LOGO': '', 'PROJECT_NAME': 'My Pet Project', 'SHOW_INCLUDE_FILES': True, 'XML_OUTPUT': 'xml' diff --git a/documentation/test_doxygen/test_layout.py b/documentation/test_doxygen/test_layout.py index e9d7fb12..db48147c 100644 --- a/documentation/test_doxygen/test_layout.py +++ b/documentation/test_doxygen/test_layout.py @@ -92,6 +92,22 @@ class NavbarMainProjectUrl(BaseTestCase): self.run_doxygen(wildcard='indexpage.xml') self.assertEqual(*self.actual_expected_contents('index.html')) +class NavbarProjectLogo(BaseTestCase): + def __init__(self, *args, **kwargs): + super().__init__(__file__, 'navbar_project_logo', *args, **kwargs) + + def test(self): + self.run_doxygen(wildcard='indexpage.xml') + self.assertEqual(*self.actual_expected_contents('index.html')) + +class NavbarProjectLogoMainProjectUrl(BaseTestCase): + def __init__(self, *args, **kwargs): + super().__init__(__file__, 'navbar_project_logo_main_project_url', *args, **kwargs) + + def test(self): + self.run_doxygen(wildcard='indexpage.xml') + self.assertEqual(*self.actual_expected_contents('index.html')) + class SearchBinary(BaseTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, 'search_binary', *args, **kwargs) diff --git a/documentation/test_python/layout_project_logo/index.html b/documentation/test_python/layout_project_logo/index.html new file mode 100644 index 00000000..b6902a10 --- /dev/null +++ b/documentation/test_python/layout_project_logo/index.html @@ -0,0 +1,30 @@ + + + + + My Python Project | My Python Project + + + + + +
+
+
+
+
+

+ My Python Project +

+
+
+
+
+ + diff --git a/documentation/test_python/layout_project_logo/mosra.jpg b/documentation/test_python/layout_project_logo/mosra.jpg new file mode 120000 index 00000000..d474bc98 --- /dev/null +++ b/documentation/test_python/layout_project_logo/mosra.jpg @@ -0,0 +1 @@ +../../../site/content/static/mosra.jpg \ No newline at end of file diff --git a/documentation/test_python/layout_project_logo_main_project_url/index.html b/documentation/test_python/layout_project_logo_main_project_url/index.html new file mode 100644 index 00000000..cbd1618e --- /dev/null +++ b/documentation/test_python/layout_project_logo_main_project_url/index.html @@ -0,0 +1,32 @@ + + + + + My Python Project | My Python Project docs + + + + + +
+
+
+
+
+

+ My Python Project +

+
+
+
+
+ + diff --git a/documentation/test_python/layout_project_logo_main_project_url/mosra.jpg b/documentation/test_python/layout_project_logo_main_project_url/mosra.jpg new file mode 120000 index 00000000..d474bc98 --- /dev/null +++ b/documentation/test_python/layout_project_logo_main_project_url/mosra.jpg @@ -0,0 +1 @@ +../../../site/content/static/mosra.jpg \ No newline at end of file diff --git a/documentation/test_python/test_layout.py b/documentation/test_python/test_layout.py index 7afaa6f0..06f376c3 100644 --- a/documentation/test_python/test_layout.py +++ b/documentation/test_python/test_layout.py @@ -84,3 +84,19 @@ class SearchOpenSearch(BaseTestCase): self.assertEqual(*self.actual_expected_contents('index.html')) self.assertTrue(os.path.exists(os.path.join(self.path, 'output', 'search-v1.js'))) self.assertEqual(*self.actual_expected_contents('opensearch.xml')) + +class ProjectLogo(BaseTestCase): + def test(self): + self.run_python({ + 'PROJECT_LOGO': 'mosra.jpg', + }) + self.assertEqual(*self.actual_expected_contents('index.html')) + +class ProjectLogoMainProjectUrl(BaseTestCase): + def test(self): + self.run_python({ + 'PROJECT_LOGO': 'mosra.jpg', + 'PROJECT_SUBTITLE': 'docs', + 'MAIN_PROJECT_URL': 'http://your.brand' + }) + self.assertEqual(*self.actual_expected_contents('index.html')) diff --git a/pelican-theme/templates/base.html b/pelican-theme/templates/base.html index 71442dfb..789d31a2 100644 --- a/pelican-theme/templates/base.html +++ b/pelican-theme/templates/base.html @@ -44,7 +44,7 @@
- {%- if M_SITE_LOGO %}{% endif -%} + {%- if M_SITE_LOGO %}{% endif -%} {{- (M_SITE_LOGO_TEXT or SITENAME)|e -}} {% if M_LINKS_NAVBAR1 or M_LINKS_NAVBAR2 %} diff --git a/pelican-theme/test/layout_brand_logo/index.html b/pelican-theme/test/layout_brand_logo/index.html new file mode 100644 index 00000000..0f2fc92e --- /dev/null +++ b/pelican-theme/test/layout_brand_logo/index.html @@ -0,0 +1,37 @@ + + + + + Brand Logo | A Pelican Blog + + + + + + + + + + + + +
+
+
+
+
+
+

Brand Logo

+
+
+
+
+
+ + diff --git a/pelican-theme/test/layout_brand_logo/index.rst b/pelican-theme/test/layout_brand_logo/index.rst new file mode 100644 index 00000000..345b81c4 --- /dev/null +++ b/pelican-theme/test/layout_brand_logo/index.rst @@ -0,0 +1,4 @@ +Brand Logo +########## + +:save_as: index.html diff --git a/pelican-theme/test/layout_brand_logo/mosra.jpg b/pelican-theme/test/layout_brand_logo/mosra.jpg new file mode 120000 index 00000000..d474bc98 --- /dev/null +++ b/pelican-theme/test/layout_brand_logo/mosra.jpg @@ -0,0 +1 @@ +../../../site/content/static/mosra.jpg \ No newline at end of file diff --git a/pelican-theme/test/test_layout.py b/pelican-theme/test/test_layout.py index 9e59a97a..2abc9da6 100644 --- a/pelican-theme/test/test_layout.py +++ b/pelican-theme/test/test_layout.py @@ -241,3 +241,28 @@ class GlobalSocialMeta(BaseTestCase): # different og:url but nothing else. self.assertEqual(*self.actual_expected_contents('index.html')) self.assertEqual(*self.actual_expected_contents('archives.html')) + +class BrandLogo(MinimalTestCase): + def __init__(self, *args, **kwargs): + super().__init__(__file__, 'brand_logo', *args, **kwargs) + + def test(self): + self.run_pelican({ + # This is the minimal that's required. Not even the M_THEME_COLOR + # is required. + 'THEME': '.', + 'PLUGIN_PATHS': ['../plugins'], + 'PLUGINS': ['m.htmlsanity'], + 'THEME_STATIC_DIR': 'static', + 'M_CSS_FILES': ['https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i', + 'static/m-dark.css'], + 'M_SITE_LOGO': 'mosra.jpg', + 'STATIC_PATHS': ['mosra.jpg'], + 'ARTICLE_PATHS': ['articles'], # doesn't exist + # Supplying empty index.html to avoid excessive hello world markup + # we don't need + 'PAGE_PATHS': ['.'], + 'M_FINE_PRINT': ''}) + + # The archives and index page should be exactly the same + self.assertEqual(*self.actual_expected_contents('index.html'))