rewrite the project as a static site generator

this removes Flask, reworks a number of library methods accordingly, and
adds generators and build commands to process the instance directory
(largely unchanged, except config.py is now config.json) and spit out
files suitable to be served by a web server such as Nginx.

there are probably some rough edges here, but overall this works.

also note, as this is no longer server software on a network, the
license has changed from AGPLv3 to GPLv3, and the "or any later version"
allowance has been removed

Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
2025-03-12 10:28:38 -05:00
parent ed12272d4d
commit 7eb485c6ae
45 changed files with 1389 additions and 1587 deletions

View File

@@ -1,44 +1,77 @@
"""Test the feed methods.
SPDX-FileCopyrightText: © 2023 Brian S. Stephan <bss@incorporeal.org>
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: GPL-3.0-only
"""
from incorporealcms.feed import serve_feed
import os
import tempfile
from incorporealcms import init_instance
from incorporealcms.feed import generate_feed
HERE = os.path.dirname(os.path.abspath(__file__))
init_instance(instance_path=os.path.join(HERE, 'instance'))
def test_unknown_type_is_404(client):
"""Test that requesting a feed type that doesn't exist is a 404."""
response = client.get('/feed/wat')
assert response.status_code == 404
def test_atom_type_generated():
"""Test that an ATOM feed can be generated."""
with tempfile.TemporaryDirectory() as tmpdir:
src_dir = os.path.join(HERE, 'instance')
generate_feed('atom', src_dir, tmpdir)
with open(os.path.join(tmpdir, 'feed', 'atom'), 'r') as feed_output:
data = feed_output.read()
assert '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<feed xmlns="http://www.w3.org/2005/Atom">' in data
assert '<id>https://example.org/</id>' in data
assert '<email>admin@example.org</email>' in data
assert '<name>Test Name</name>' in data
# forced-no-title.md
assert '<title>example.org</title>' in data
assert '<link href="https://example.org/forced-no-title"/>' in data
assert '<id>tag:example.org,2023-12-01:/forced-no-title</id>' in data
assert '<content type="html">&lt;p&gt;some words are here&lt;/p&gt;</content>' in data
# more-metadata.md
assert '<title>title for the page - example.org</title>' in data
assert '<link href="https://example.org/more-metadata"/>' in data
assert '<id>tag:example.org,2025-03-16:/more-metadata</id>' in data
assert '<content type="html">&lt;p&gt;hello&lt;/p&gt;</content>' in data
def test_atom_type_is_200(client):
"""Test that requesting an ATOM feed is found."""
response = client.get('/feed/atom')
assert response.status_code == 200
assert 'application/atom+xml' in response.content_type
print(response.text)
def test_rss_type_generated():
"""Test that an RSS feed can be generated."""
with tempfile.TemporaryDirectory() as tmpdir:
src_dir = os.path.join(HERE, 'instance')
generate_feed('rss', src_dir, tmpdir)
with open(os.path.join(tmpdir, 'feed', 'rss'), 'r') as feed_output:
data = feed_output.read()
assert '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<rss xmlns:atom="http://www.w3.org/2005/Atom"' in data
assert 'xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">' in data
assert '<link>https://example.org</link>' in data
# forced-no-title.md
assert '<title>example.org</title>' in data
assert '<link>https://example.org/forced-no-title</link>' in data
assert '<guid isPermaLink="false">tag:example.org,2023-12-01:/forced-no-title</guid>' in data
assert '<description>&lt;p&gt;some words are here&lt;/p&gt;</description>' in data
assert '<author>admin@example.org (Test Name)</author>' in data
# more-metadata.md
assert '<title>title for the page - example.org</title>' in data
assert '<link>https://example.org/more-metadata</link>' in data
assert '<guid isPermaLink="false">tag:example.org,2025-03-16:/more-metadata</guid>' in data
assert '<description>&lt;p&gt;hello&lt;/p&gt;</description>' in data
assert '<author>admin@example.org (Test Name)</author>' in data
def test_rss_type_is_200(client):
"""Test that requesting an RSS feed is found."""
response = client.get('/feed/rss')
assert response.status_code == 200
assert 'application/rss+xml' in response.content_type
print(response.text)
def test_feed_generator_atom(app):
"""Test the root feed generator."""
with app.test_request_context():
content = serve_feed('atom')
assert b'<id>https://example.com/</id>' in content.data
assert b'<email>admin@example.com</email>' in content.data
assert b'<name>Test Name</name>' in content.data
def test_feed_generator_rss(app):
"""Test the root feed generator."""
with app.test_request_context():
content = serve_feed('rss')
assert b'<author>admin@example.com (Test Name)</author>' in content.data
def test_multiple_runs_without_error():
"""Test that we can run the RSS and Atom feed generators in any order."""
with tempfile.TemporaryDirectory() as tmpdir:
src_dir = os.path.join(HERE, 'instance')
generate_feed('atom', src_dir, tmpdir)
generate_feed('rss', src_dir, tmpdir)
generate_feed('atom', src_dir, tmpdir)
generate_feed('rss', src_dir, tmpdir)