From cfefbaed22d89009af0aa85fe491d927e470456e Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Mon, 13 Apr 2026 22:59:38 +0100 Subject: [PATCH] Update docs --- docs/_static/theme-basic.zip | Bin 1449 -> 0 bytes docs/themes.rst | 62 ++++++++++++++++------------------- pelican/tests/test_theme.py | 37 +++++++++++++++++++++ 3 files changed, 66 insertions(+), 33 deletions(-) delete mode 100644 docs/_static/theme-basic.zip diff --git a/docs/_static/theme-basic.zip b/docs/_static/theme-basic.zip deleted file mode 100644 index d1e4754a44fcedc4c1c16f34b3782c225d13da3c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1449 zcmWIWW@h1H0D)14dG;9W((8wS6ac%z{v7~nSlXJ z1ifa@?NLjPW7=i{?%>6U=(#wrR2My!>G1rlT`v1U_xwrQE(L(%f)Tjl0irVcqV9wdeM| zwVw5WTWqfF5yn$XK6f;kTIT2;dZJdt<=683ZE3CjyUv8GiV3#2*Urp$td2bTa^u~( zTj~+vbUhI@oOt2BD=tYafd%(8UroP>%kc!aUgmd{=n_OXCb<|I-Y-^b`Ayx2)hI}K zFHQY!m-4{A#)^@F;SUo7gA_KSic2bUQuTm_f&<)inU+bm9tK6L!WXNgaq zH*?M2re0ff@K_P&?Z}*|*CeD?X8d7Tc_TsNVXm%ik8Z#fH?ECG89HUMG8XN!3$6^2 z+O0D0qgU_BQm?voMIrLvZ`z&?d1)Zy_{i*g?9Ov<8qc;C=Vo`Nl}A znLqev^PF&5skrlA*&&tSOZ#){TT3#z1N^z!vXzYXEXdc~#HG`7S5JBU=@WU9mCtofH4rmK2RR&CybLe@`RGfvuzJzi+Mb+X1Yvsv6LW?VT@0-7fU7~VR9n6P}w3dxsfv4CtAX0Ajw%K>f{avlYm3d*Bc zO~sW%A*KQo5W|wjE-a=Z)11OPn40F4A?7(7N|W*1~5 z*P|N=$vi+~L74}uvAD7hazOmTW-L-h0-6uXNEqg`vH?Sofei?`f!VPGSk^Ky00373 BtK - {% endblock %} - -1. On the first line, we extend the ``base.html`` template from the ``simple`` - theme, so we don't have to rewrite the entire file. -2. On the third line, we open the ``head`` block which has already been defined - in the ``simple`` theme. -3. On the fourth line, the function ``super()`` keeps the content previously - inserted in the ``head`` block. -4. On the fifth line, we append a stylesheet to the page. -5. On the last line, we close the ``head`` block. - -This file will be extended by all the other templates, so the stylesheet will -be linked from all pages. - -style.css -""""""""" - -The second file is the ``static/css/style.css`` CSS stylesheet: +The file is ``static/css/main.css`` (the default ``CSS_FILE``): .. code-block:: css @@ -663,10 +637,32 @@ The second file is the ``static/css/style.css`` CSS stylesheet: margin-top : 1em ; } -Download -"""""""" +Custom templates +"""""""""""""""" -You can download this example theme :download:`here <_static/theme-basic.zip>`. +If you want to customise the templates as well, you can extend them. For +example, to add a custom footer, create a ``templates/base.html``: + +.. code-block:: html+jinja + + {% extends "!simple/base.html" %} + + {% block footer %} +

Custom footer

+ {{ super() }} + {% endblock %} + +1. On the first line, we extend the ``base.html`` template from the ``simple`` + theme, so we don't have to rewrite the entire file. +2. On the third line, we open the ``footer`` block which has already been + defined in the ``simple`` theme. +3. On the fourth line, we insert the extra footer content. +4. On the fifth line, the function ``super()`` keeps the content previously + inserted in the ``head`` block. +5. On the last line, we close the ``footer`` block. + +This file will be extended by all the other templates, so the custom footer +will appear on all pages. .. Links diff --git a/pelican/tests/test_theme.py b/pelican/tests/test_theme.py index 4e47eb2a..7012b2e4 100644 --- a/pelican/tests/test_theme.py +++ b/pelican/tests/test_theme.py @@ -218,5 +218,42 @@ class TestTemplateInheritance(LoggedTestCase): content, ) + def test_css_only_theme(self): + """A theme with only a static/css/main.css file (no templates) + should work by falling back to the simple theme's templates.""" + + css_only_theme = mkdtemp(prefix="pelican_test_css_only_theme.") + css_dir = os.path.join(css_only_theme, "static", "css") + os.makedirs(css_dir) + with open(os.path.join(css_dir, "main.css"), "w") as f: + f.write("body { margin: 0; }") + + try: + settings = read_settings( + path=None, + override={ + "THEME": css_only_theme, + "PATH": CONTENT_DIR, + "OUTPUT_PATH": self.temp_output, + "CACHE_PATH": self.temp_cache, + "SITEURL": "http://example.com", + }, + ) + + pelican = Pelican(settings=settings) + mute(True)(pelican.run)() + + with open(os.path.join(self.temp_output, "test-md-file.html")) as f: + content = f.read() + + self.assertIn( + 'href="http://example.com/theme/css/main.css"', + content, + ) + self.assertIn("Proudly powered by", content) + finally: + rmtree(css_only_theme) + + if __name__ == "__main__": unittest.main()