feat: scaffold plain .html pages that need no server config
This commit is contained in:
parent
5e2e709496
commit
2ea4f461d3
2 changed files with 31 additions and 22 deletions
|
|
@ -41,13 +41,16 @@ DEFAULT_LANG = "en"
|
||||||
THEME = "theme"
|
THEME = "theme"
|
||||||
|
|
||||||
# The plugin reads the allowed elements and attributes from the Mews DTD and
|
# The plugin reads the allowed elements and attributes from the Mews DTD and
|
||||||
# brings every page inside that subset. It only touches files ending .xhtml,
|
# brings every page inside that subset.
|
||||||
# so everything has to be written out under that suffix.
|
|
||||||
PLUGINS = ["pelican.plugins.mews"]
|
PLUGINS = ["pelican.plugins.mews"]
|
||||||
|
|
||||||
ARTICLE_URL = ARTICLE_SAVE_AS = "{{slug}}.xhtml"
|
# This whole site is Mews, so its pages are plain .html: a server sends those
|
||||||
PAGE_URL = PAGE_SAVE_AS = "{{slug}}.xhtml"
|
# as text/html, which section 7.1 asks for so a small markup error still shows
|
||||||
INDEX_SAVE_AS = "index.xhtml"
|
# as a page, and index.html is the directory index everywhere. The plugin
|
||||||
|
# defaults to .xhtml instead, for sites that are only partly Mews.
|
||||||
|
MEWS_SUFFIX = ".html"
|
||||||
|
ARTICLE_URL = ARTICLE_SAVE_AS = "{{slug}}.html"
|
||||||
|
PAGE_URL = PAGE_SAVE_AS = "{{slug}}.html"
|
||||||
|
|
||||||
# Markdown has to produce XML for the plugin to parse. Tables and definition
|
# Markdown has to produce XML for the plugin to parse. Tables and definition
|
||||||
# lists are both in the Mews subset but need their extensions turned on.
|
# lists are both in the Mews subset but need their extensions turned on.
|
||||||
|
|
@ -59,7 +62,11 @@ MARKDOWN = {{
|
||||||
}},
|
}},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
# Mews pages carry no author styling, so there is nothing for these to show.
|
# Every page written under MEWS_SUFFIX goes through the plugin, and Pelican
|
||||||
|
# falls back to its own HTML templates for these when the theme has none. They
|
||||||
|
# have nothing to show on a site like this, so they stay off; give them
|
||||||
|
# templates in theme/templates/ if you want them.
|
||||||
|
DIRECT_TEMPLATES = ["index"]
|
||||||
AUTHOR_SAVE_AS = CATEGORY_SAVE_AS = TAG_SAVE_AS = ""
|
AUTHOR_SAVE_AS = CATEGORY_SAVE_AS = TAG_SAVE_AS = ""
|
||||||
AUTHORS_SAVE_AS = CATEGORIES_SAVE_AS = TAGS_SAVE_AS = ARCHIVES_SAVE_AS = ""
|
AUTHORS_SAVE_AS = CATEGORIES_SAVE_AS = TAGS_SAVE_AS = ARCHIVES_SAVE_AS = ""
|
||||||
# Pelican writes several feeds by default and they are all broken until
|
# Pelican writes several feeds by default and they are all broken until
|
||||||
|
|
@ -115,7 +122,7 @@ ARTICLE = """\
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ article.title }}</h1>
|
<h1>{{ article.title }}</h1>
|
||||||
{{ article.content }}
|
{{ article.content }}
|
||||||
<p><a href="index.xhtml">All posts</a></p>
|
<p><a href="index.html">All posts</a></p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -125,7 +132,7 @@ PAGE = """\
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ page.title }}</h1>
|
<h1>{{ page.title }}</h1>
|
||||||
{{ page.content }}
|
{{ page.content }}
|
||||||
<p><a href="index.xhtml">All posts</a></p>
|
<p><a href="index.html">All posts</a></p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -157,7 +164,8 @@ A Mews site. The pages follow [Mews Profile 0.1](https://mews.page/spec/0.1).
|
||||||
uv run pelican content
|
uv run pelican content
|
||||||
```
|
```
|
||||||
|
|
||||||
The finished pages land in `output/`. To work on it with a reload on save:
|
The finished pages land in `output/`, as plain `.html` that any web server
|
||||||
|
serves correctly with no configuration. To work on it with a reload on save:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
uv run pelican --autoreload --listen content
|
uv run pelican --autoreload --listen content
|
||||||
|
|
@ -165,12 +173,7 @@ uv run pelican --autoreload --listen content
|
||||||
|
|
||||||
## Publish it
|
## Publish it
|
||||||
|
|
||||||
Copy `output/` to any web server. Two things are worth setting:
|
Copy `output/` to any web server. Nothing to configure.
|
||||||
|
|
||||||
- Serve `.xhtml` files as `text/html`. Section 7.1 of the spec asks for that,
|
|
||||||
so a browser still shows a page carrying a small markup error.
|
|
||||||
- Make `index.xhtml` the directory index, since the plugin only processes
|
|
||||||
files under that suffix. In Caddy: `file_server {{ index index.xhtml }}`.
|
|
||||||
|
|
||||||
## Subscribe to it
|
## Subscribe to it
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,15 @@ def test_the_settings_are_valid_python(tmp_path):
|
||||||
)
|
)
|
||||||
assert settings["SITENAME"] == "Signal Bars"
|
assert settings["SITENAME"] == "Signal Bars"
|
||||||
assert settings["PLUGINS"] == ["pelican.plugins.mews"]
|
assert settings["PLUGINS"] == ["pelican.plugins.mews"]
|
||||||
# The plugin only touches this suffix, so everything has to be saved under it.
|
# A site that is Mews throughout writes plain .html: servers send that as
|
||||||
assert settings["ARTICLE_SAVE_AS"].endswith(".xhtml")
|
# text/html (section 7.1) and index.html is the directory index everywhere.
|
||||||
assert settings["INDEX_SAVE_AS"].endswith(".xhtml")
|
# The suffix the plugin acts on has to agree with where pages are saved.
|
||||||
|
assert settings["MEWS_SUFFIX"] == ".html"
|
||||||
|
assert settings["ARTICLE_SAVE_AS"].endswith(".html")
|
||||||
|
assert settings["PAGE_SAVE_AS"].endswith(".html")
|
||||||
|
# Pelican falls back to its own HTML for any direct template the theme
|
||||||
|
# lacks, and with .html the plugin would choke on it.
|
||||||
|
assert settings["DIRECT_TEMPLATES"] == ["index"]
|
||||||
assert settings["MARKDOWN"]["output_format"] == "xhtml"
|
assert settings["MARKDOWN"]["output_format"] == "xhtml"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -62,11 +68,11 @@ def test_the_scaffolded_site_builds_conforming_pages(tmp_path):
|
||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
assert built.returncode == 0, built.stderr
|
assert built.returncode == 0, built.stderr
|
||||||
pages = sorted((site / "output").glob("*.xhtml"))
|
pages = sorted((site / "output").glob("*.html"))
|
||||||
assert [p.name for p in pages] == ["first-post.xhtml", "index.xhtml"]
|
assert [p.name for p in pages] == ["first-post.html", "index.html"]
|
||||||
for page in pages:
|
for page in pages:
|
||||||
report = validate_file(str(page))
|
report = validate_file(str(page))
|
||||||
assert report.conforms, "\n".join(str(f) for f in report.failures)
|
assert report.conforms, "\n".join(str(f) for f in report.failures)
|
||||||
# Section 6.1: the index has to be subscribable.
|
# Section 6.1: the index has to be subscribable.
|
||||||
index = (site / "output" / "index.xhtml").read_text()
|
index = (site / "output" / "index.html").read_text()
|
||||||
assert '<li><a href="first-post.xhtml">' in index
|
assert '<li><a href="first-post.html">' in index
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue