fix where the feed generator outputs to, and also output error pages
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
4644aea4b0
commit
d52fc4df9a
@ -8,10 +8,16 @@ import logging
|
|||||||
import os
|
import os
|
||||||
from logging.config import dictConfig
|
from logging.config import dictConfig
|
||||||
|
|
||||||
|
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||||
from termcolor import cprint
|
from termcolor import cprint
|
||||||
|
|
||||||
from incorporealcms.config import Config
|
from incorporealcms.config import Config
|
||||||
|
|
||||||
|
jinja_env = Environment(
|
||||||
|
loader=PackageLoader('incorporealcms'),
|
||||||
|
autoescape=select_autoescape(),
|
||||||
|
)
|
||||||
|
|
||||||
# dynamically generate version number
|
# dynamically generate version number
|
||||||
try:
|
try:
|
||||||
# packaged/pip install -e . value
|
# packaged/pip install -e . value
|
||||||
|
21
incorporealcms/error_pages.py
Normal file
21
incorporealcms/error_pages.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
"""Process the error page templates.
|
||||||
|
|
||||||
|
SPDX-FileCopyrightText: © 2025 Brian S. Stephan <bss@incorporeal.org>
|
||||||
|
SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
|
||||||
|
from incorporealcms import jinja_env
|
||||||
|
from incorporealcms.config import Config
|
||||||
|
|
||||||
|
|
||||||
|
def generate_error_pages(dest_dir: str) -> None:
|
||||||
|
"""Process the error pages and place them in the output dir.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
dest_dir: the directory to place the error pages in, for a web server to serve
|
||||||
|
"""
|
||||||
|
for template_name in ['400.html', '404.html', '500.html']:
|
||||||
|
template = jinja_env.get_template(template_name)
|
||||||
|
with open(os.path.join(dest_dir, template_name), 'w') as error_page:
|
||||||
|
error_page.write(template.render(config=Config))
|
@ -13,18 +13,13 @@ import os
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
import markdown
|
import markdown
|
||||||
from jinja2 import Environment, PackageLoader, select_autoescape
|
|
||||||
from markupsafe import Markup
|
from markupsafe import Markup
|
||||||
|
|
||||||
|
from incorporealcms import jinja_env
|
||||||
from incorporealcms.config import Config
|
from incorporealcms.config import Config
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
jinja_env = Environment(
|
|
||||||
loader=PackageLoader('incorporealcms'),
|
|
||||||
autoescape=select_autoescape(),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_meta_str(md, key):
|
def get_meta_str(md, key):
|
||||||
"""Provide the page's (parsed in Markup obj md) metadata for the specified key, or '' if unset."""
|
"""Provide the page's (parsed in Markup obj md) metadata for the specified key, or '' if unset."""
|
||||||
|
@ -12,6 +12,7 @@ import tempfile
|
|||||||
from termcolor import cprint
|
from termcolor import cprint
|
||||||
|
|
||||||
from incorporealcms import __version__, init_instance
|
from incorporealcms import __version__, init_instance
|
||||||
|
from incorporealcms.error_pages import generate_error_pages
|
||||||
from incorporealcms.feed import generate_feed
|
from incorporealcms.feed import generate_feed
|
||||||
from incorporealcms.markdown import handle_markdown_file_path
|
from incorporealcms.markdown import handle_markdown_file_path
|
||||||
|
|
||||||
@ -61,8 +62,12 @@ class StaticSiteGenerator(object):
|
|||||||
|
|
||||||
# generate the feeds
|
# generate the feeds
|
||||||
cprint("generating feeds", 'green')
|
cprint("generating feeds", 'green')
|
||||||
generate_feed('atom', self.instance_dir, self.output_dir)
|
generate_feed('atom', self.instance_dir, tmp_output_dir)
|
||||||
generate_feed('rss', self.instance_dir, self.output_dir)
|
generate_feed('rss', self.instance_dir, tmp_output_dir)
|
||||||
|
|
||||||
|
# generate the error pages
|
||||||
|
cprint("generating error pages", 'green')
|
||||||
|
generate_error_pages(tmp_output_dir)
|
||||||
|
|
||||||
# move temporary dir to the destination
|
# move temporary dir to the destination
|
||||||
old_output_dir = f'{self.output_dir}-old-{os.path.basename(tmp_output_dir)}'
|
old_output_dir = f'{self.output_dir}-old-{os.path.basename(tmp_output_dir)}'
|
||||||
|
@ -13,7 +13,7 @@ SPDX-License-Identifier: GPL-3.0-only
|
|||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h1>NOT FOUND</h1>
|
<h1>NOT FOUND</h1>
|
||||||
<p>Sorry, <b><tt>{{ request.path }}</tt></b> does not seem to exist, at least not anymore.</p>
|
<p>Sorry, the file you requested does not seem to exist, at least not anymore.</p>
|
||||||
<p>It's possible you followed a dead link on this site, in which case I would appreciate it if you could email me at
|
<p>It's possible you followed a dead link on this site, in which case I would appreciate it if you could email me at
|
||||||
{{ config.CONTACT_EMAIL }} and I can take a look. I make an effort to symlink old content to its new location,
|
{{ config.CONTACT_EMAIL }} and I can take a look. I make an effort to symlink old content to its new location,
|
||||||
so old links and URLs should, generally speaking, work.</p>
|
so old links and URLs should, generally speaking, work.</p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user