pengutronix / flamingo Goto Github PK
View Code? Open in Web Editor NEWpython3-based, pelican-inspired static site generator
Home Page: https://flamingo-web.org/
License: Apache License 2.0
python3-based, pelican-inspired static site generator
Home Page: https://flamingo-web.org/
License: Apache License 2.0
In flamingo v0.11 the HTML parser (flamingo/plugins/html.py
) has a tendency to alter the structure of HTML documents.
In my current project with HTML_PARSER_RAW_HTML = False
I can reproduce the behavior with this HTML document. ([...]
means that there is some content left out.)
template: raw.html
<div class="main">
<div>
<a href="/">Zurück zur Hauptseite</a><br><br>
[...]
<h4>Cookies</h4>
<p>Diese Webseite verwendet keine Cookies oder ähnliche Technologien.</p>
</div>
<h2 id="footnote">Eine Veranstaltung des <a href="https://stratum0.org">Stratum 0</a></h2>
<a style="display:none;" rel="me" href="https://chaos.social/@HackenOpenAir">Mastodon</a>
</div>
This generates the following output:
<div class="main">
<div>
<a href="/">Zurück zur Hauptseite</a><br><br>
[...]
<h4>Externe Inhalte</h4>
<p>Zur Darstellung der Webseite werden Inhalte von www.openstreetmap.org nachgeladen.</p>
<h4>Cookies</h4>
<p>Diese Webseite verwendet keine Cookies oder ähnliche Technologien.</p>
</p></br></br></br></br></br></br></div>
<h2 id="footnote">Eine Veranstaltung des <a href="https://stratum0.org">Stratum 0</a></h2>
<a href="https://chaos.social/@HackenOpenAir" rel="me" style="display:none;">Mastodon</a>
</div>
The main problem here are the extra </p></br></br></br></br></br></br>
that are inserted by the HTML-parser.
I understand that Beautiful Soup is used to alter the src-attributes of images when using the media-API. But in most use-cases an altered HTML-structure as a whole is not acceptable.
When setting HTML_PARSER_RAW_HTML = True
this behavior disappears.
Hi,
I am interested in the main differences between Flamingo and Pelican. Why did you start coding this and not just use pelican? What is the problem you want to solve that is not solved by pelican?
Maybe this is something other ppl are interested in. IMHO it would be nice to include it in the README because it might be a pro argument to use your software...
Thanks
Philip
With Python 3.10 the sphinx-themes
feature breaks:
make html
. env/bin/activate && \
flamingo build -s settings.py menu.py
ERROR:flamingo.core.PluginManager:setup of 'flamingo.plugins.SphinxThemes' failed
Traceback (most recent call last):
File "/home/bbu/scm/ptx/ptx-admin-workplace-mr/ptx-infrastructure-manual/env/lib/python3.10/site-packages/flamingo/core/utils/imports.py", line 19, in acquire
item = importlib.import_module(item)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'flamingo.plugins.SphinxThemes'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/bbu/scm/ptx/ptx-admin-workplace-mr/ptx-infrastructure-manual/env/lib/python3.10/site-packages/flamingo/core/plugins/plugin_manager.py", line 91, in __init__
plugin_class, plugin_path = acquire(plugin)
File "/home/bbu/scm/ptx/ptx-admin-workplace-mr/ptx-infrastructure-manual/env/lib/python3.10/site-packages/flamingo/core/utils/imports.py", line 34, in acquire
item = getattr(module, attr_name)
AttributeError: module 'flamingo.plugins' has no attribute 'SphinxThemes'
Removing the catchall in https://github.com/pengutronix/flamingo/blob/master/flamingo/plugins/__init__.py#L50 yields the actual problem:
$make html
. env/bin/activate && \
flamingo build -s settings.py menu.py
ERROR:flamingo.core.PluginManager:setup of 'flamingo.plugins.HTML' failed
Traceback (most recent call last):
File "/home/chris/work/Projects/github/flamingo/flamingo/core/utils/imports.py", line 19, in acquire
item = importlib.import_module(item)
File "/home/chris/.pyenv/versions/3.10.2/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/chris/work/Projects/github/flamingo/flamingo/plugins/__init__.py", line 49, in <module>
from .sphinx_themes.plugin import SphinxThemes # NOQA
File "/home/chris/work/Projects/github/flamingo/flamingo/plugins/sphinx_themes/plugin.py", line 10, in <module>
from sphinx.jinja2glue import _tobool, _todim, _toint, accesskey
File "/home/chris/work/Projects/ptxadmin/ptx-infrastructure-manual/env/lib/python3.10/site-packages/sphinx/jinja2glue.py", line 20, in <module>
from sphinx.application import TemplateBridge
File "/home/chris/work/Projects/ptxadmin/ptx-infrastructure-manual/env/lib/python3.10/site-packages/sphinx/application.py", line 32, in <module>
from sphinx.config import Config
File "/home/chris/work/Projects/ptxadmin/ptx-infrastructure-manual/env/lib/python3.10/site-packages/sphinx/config.py", line 21, in <module>
from sphinx.util import logging
File "/home/chris/work/Projects/ptxadmin/ptx-infrastructure-manual/env/lib/python3.10/site-packages/sphinx/util/__init__.py", line 41, in <module>
from sphinx.util.typing import PathMatcher
File "/home/chris/work/Projects/ptxadmin/ptx-infrastructure-manual/env/lib/python3.10/site-packages/sphinx/util/typing.py", line 37, in <module>
from types import Union as types_Union
ImportError: cannot import name 'Union' from 'types' (/home/chris/.pyenv/versions/3.10.2/lib/python3.10/types.py)
This was fixed with Sphinx 4.2.0 (https://www.sphinx-doc.org/en/master/changes.html#release-4-2-0-released-sep-12-2021 ) (and PR sphinx-doc/sphinx#9512 ).
But this release (and newer) in incompatible with the flamingo-integration.
There is none. We need some.
I'm not sure whether this would introduce new problems or if it's considered bad practice for some reason.
Problem:
When creating a new website with make html
in e.g., ~/my-site/, some resources including bootstrap are not loaded properly. The reason is that some of the links in the base.html template are currently included with absolute paths:
<link rel="stylesheet" href="/static/bootstrap-4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/custom.css">
<link rel="shortcut icon" href="/favicon.ico">
This has puzzled me before, because the website looked fine in the live server but not when clicking on the html files directly. As a newcomer, this is a somewhat demotivating hurdle. Do you see any problem changing them to relative paths? E.g.:
<link rel="stylesheet" href="static/bootstrap-4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="static/custom.css">
<link rel="shortcut icon" href="favicon.ico">
That would fix the problem and make it easier to get started or when creating projects meant for offline use. On the other hand, I'm not sure if that would break compatibility or some standards elsewhere.
While reviewing #29 I stumbled over the fact that we do not have any documentation on the sphinx_theme
plugin jet - despite the fact that the documentation itself used the plugin.
We should add a section to the plugins-chapter in the documentation.
Tried the longer example for an image directive from https://docutils.sourceforge.io/docs/ref/rst/directives.html#images
.. image:: picture.jpeg
:height: 100px
:width: 200 px
:scale: 50 %
:alt: alternate text
:align: right
Then run flamingo server -s settings.py --debug
.
This shows
And the console output is
$ flamingo server -s settings.py --debug
ERROR:flamingo:content/index.rst:45: Error in "image" directive:
starting server on http://localhost:8080/
This is missing some useful debug output, even though the --debug flag has been passed.
Same thing with flamingo build -s settings.py --debug
023-02-09 06:53:27 gorgon flamingo.core.PluginManager[1493560] DEBUG running plugin hook 'media_added'
2023-02-09 06:53:27 gorgon flamingo.core.PluginManager[1493560] DEBUG running Thumbnails.media_added
2023-02-09 06:53:27 gorgon flamingo.plugins.Thumbnails[1493560] DEBUG processing index.rst:pool.jpeg
2023-02-09 06:53:27 gorgon flamingo.plugins.Thumbnails[1493560] DEBUG setup thumbnail for index.rst:pool.jpeg (6ef920df1617bff6aecf0b084df62c6c)
2023-02-09 06:53:27 gorgon flamingo.core.media[1493560] DEBUG thumbs/6ef920df1617bff6aecf0b084df62c6c.jpeg added to index.rst
2023-02-09 06:53:27 gorgon flamingo.plugins.reStructuredText[1493560] DEBUG <string>:38: (ERROR/3) Error in "image" directive:
unknown option: "scale".
.. image:: pool.jpeg
:height: 100px
:width: 200 px
:scale: 50 %
:alt: alternate text
:align: right
NoneType: None
2023-02-09 06:53:27 gorgon flamingo[1493560] ERROR content/index.rst:45: Error in "image" directive:
This looks like the error message is truncated to a single line when running without --debug
or in as a server. Also, the useful part of the error is printed as a debug message.
Hi!
I'm trying to include an image in a blog post using markdown. This is my content file:
title: Homepage
author: alice
published: 2020-05-01
modified: 2020-05-02
description: A test description
tags: [ドイツ, アメリカ]
output: index.html
template: blog-post.html
# Home World
Welcome everybody else!
<picture>
<source srcset="media/P4171125-768x576.webp"/>
<img alt="Beatles" src="media/P4171125-768x576.jpg" style="width:auto;"/>
</picture>
<img alt="Alt text" src="media/P4171125-768x576.jpg" title="Optional title"/></p>
![alt text](media/P4171125-768x576.jpg "title")
After making the html file, the image sources are cut out (except for the alternative source in the picture tag):
<h1>Home World</h1>
<p>Welcome everybody else!</p>
<p><picture>
<source srcset="media/P4171125-768x576.webp"/>
<img alt="Beatles" src style="width:auto;"/>
</picture></p>
<p><img alt="Alt text" src title="Optional title"/></p>
<p><img alt="alt text" src title="title"/></p>
</div>
</main>
<footer class="border-top">
</footer>
<script src="/static/jquery/jquery-3.4.1.min.js"></script>
<script src="/static/bootstrap-4.3.1/js/bootstrap.min.js"></script>
</body>
</html>
the template file looks like this:
{% extends "base.html" %}
{% block structured_data %}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "{{ context.settings.PROJECT_URL }}{{ content.url }}"
},
"headline": "{{ content.content_title }}",
"image": [
"https://example.com/photos/1x1/photo.jpg",
"https://example.com/photos/4x3/photo.jpg",
"https://example.com/photos/16x9/photo.jpg"
],
"datePublished": "{{ content.published }}",
"dateModified": "{{ content.modified }}",
"author": {
"@type": "Person",
"name": "{{ content.author }}"
},
"publisher": {
"@type": "Organization",
"name": "{{ context.settings.PROJECT_NAME }}",
"logo": {
"@type": "ImageObject",
"url": "https://google.com/logo.jpg"
}
},
"description": "{{ content.description }}"
}
</script>
{% endblock %}
{% block title %}{{ context.settings.PROJECT_NAME }} - {% if content.title %}{{ content.title }}{% else %}{{ content.content_title }}{% endif %}{% endblock %}
{% block content %}
<h1>{{ content.content_title }}</h1>
{{ content.content_body }}
{% endblock %}
As far as I understand it, I have to include the images in the article in order for them to appear in the media content set. But I'm a bit stuck because when I include them, they are cut out. My next solution would be to include them, have them cut out, and then reinclude them with jinja, but that seemed a bit too complicated for a simple picture, so I don't know how to proceed.
In contrast, rst seems to work fine. This:
Home World
==========
Welcome everybody else!
.. image:: media/P4171125-768x576.webp
.. image:: media/P7121696-768x576.jpg
:alt: My bar image
:title: My bar image
This is the caption of my bar image.
produces meaningful html (I deleted some whitespace):
<h1>Home World</h1>
<p>Welcome everybody else!</p>
<img src="/media/P4171125-768x576.webp"
style="
">
<div class="image"
style="
"><img src="/media/P7121696-768x576.jpg
alt="My bar image"
title="My bar image"
style="
">
<div class="caption"
style="
"><p>This is the caption of my bar image.</p>
</div>
</div>
</div>
</main>
<footer class="border-top">
</footer>
<script src="/static/jquery/jquery-3.4.1.min.js"></script>
<script src="/static/bootstrap-4.3.1/js/bootstrap.min.js"></script>
</body>
</html>
I'm a bit stuck with this issue and didn't find out how to solve it through the documentation so far. I also checked the python-markdown documentation for a possible plugin, but didn't find any (and image handling is not listed among the differences to regular markdown). If the sources are supposed to be cut out, the fact that the "srcset" isn't seems like a bug to me. Any ideas or easy solutions to this? Thanks a lot!
When writing a page in rst, i do things like
{% for l in [1,2,3,4] -%}
* Test{{l}}tseT
{% endfor %}
I actually iterate over context.contents but this is enough as a simple test case.
I expect the rst to be rendered to
* Test1tseT
* Test2tseT
* Test3tseT
* Test4tseT
and this renders to a fine unordered list.
but i can see, that this is rendered to html first:
<div class="section" id="fehlererzeugung-bei-rst-jinja">
{% for a in [1,2,3,4] %}
* Test{{a}}tseT
{% endfor %}</div>
</div>
and is not interpreted as rst.
Hi,
when I change away from the default "catergoy-1" & "category-2" to let's say categories "en" and "de" and then have files therein, I cannot generate a correct menu. The html is generated, but for the menu to show the new category I can manually edit the settings.py to the new names of categories - but that is not the intended way I suspect?
Hello how i can install locally with windows flamingo?
Currently it's not possible to run one test instead of the whole test suite:
$ tox -- tests/test_core_settings.py::test_overlaying_settings
GLOB sdist-make: /home/rsc/git/flamingo/setup.py
python recreate: /home/rsc/git/flamingo/.tox/python
python installdeps: pytest, pytest-aiohttp, pytest-cov, tests/flamingo-test-package/
python inst: /home/rsc/git/flamingo/.tox/.tmp/package/1/flamingo-1.7.1.zip
python installed: aiohttp==3.8.1,aiosignal==1.2.0,alabaster==0.7.12,async-timeout==4.0.2,attrs==21.4.0,Babel==2.10.1,beautifulsoup4==4.11.1,certifi==2021.10.8,chardet==4.0.0,charset-normalizer==2.0.12,coloredlogs==15.0.1,coverage==6.3.2,docutils==0.16,feedgen==0.7.0,flamingo @ file:///home/rsc/git/flamingo/.tox/.tmp/package/1/flamingo-1.7.1.zip,flamingo-test-package @ file:///home/rsc/git/flamingo/tests/flamingo-test-package,frozenlist==1.3.0,humanfriendly==10.0,idna==3.3,imagesize==1.3.0,importlib-metadata==4.11.3,iniconfig==1.1.1,Jinja2==3.1.2,lxml==4.8.0,Markdown==3.3.7,MarkupSafe==2.1.1,multidict==6.0.2,packaging==21.3,Pillow==9.1.0,pluggy==1.0.0,py==1.11.0,Pygments==2.12.0,pyparsing==3.0.8,pytest==7.1.2,pytest-aiohttp==1.0.4,pytest-asyncio==0.18.3,pytest-cov==3.0.0,python-dateutil==2.8.2,pytz==2022.1,PyYAML==6.0,requests==2.27.1,rlpython==0.8.4,six==1.16.0,snowballstemmer==2.2.0,soupsieve==2.3.2.post1,Sphinx==4.0.3,sphinx-rtd-theme==0.5.2,sphinxcontrib-applehelp==1.0.2,sphinxcontrib-devhelp==1.0.2,sphinxcontrib-htmlhelp==2.0.0,sphinxcontrib-jsmath==1.0.1,sphinxcontrib-qthelp==1.0.3,sphinxcontrib-serializinghtml==1.1.5,tomli==2.0.1,urllib3==1.26.9,yarl==1.7.2,zipp==3.8.0
python run-test-pre: PYTHONHASHSEED='3143421460'
python run-test: commands[0] | pytest --cov=/home/rsc/git/flamingo/.tox/python/lib/python3.9/site-packages/flamingo
============================================================================ test session starts ============================================================================
platform linux -- Python 3.9.2, pytest-7.1.2, pluggy-1.0.0 -- /home/rsc/git/flamingo/.tox/python/bin/python
cachedir: .tox/python/.pytest_cache
rootdir: /home/rsc/git/flamingo, configfile: pytest.ini
plugins: cov-3.0.0, aiohttp-1.0.4, flamingo-1.7.1, asyncio-0.18.3
asyncio: mode=auto
collected 78 items
tests/test_core_context_build.py::test_empty_build PASSED [ 1%]
tests/test_core_context_build.py::test_basic_build PASSED [ 2%]
tests/test_core_context_build.py::test_chardet PASSED [ 3%]
tests/test_core_data_model.py::test_q_api PASSED [ 5%]
...
As one can see, it collected all 78 items and doesn't deselect any, then runs all tests.
Installing flamingo with pip2 or pip fails on import with this backtrace:
$ pip install flamingo
Collecting flamingo
Using cached https://files.pythonhosted.org/packages/86/58/d53a3dc11916acd1b9ec17966b23bc4868da8a22aa6012600730c48a837d/flamingo-0.10.4.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/run/user/rfigura/pip-install-3RYxRR/flamingo/setup.py", line 7, in <module>
import flamingo
File "flamingo/__init__.py", line 3, in <module>
from flamingo.core.plugins.hooks import hook # NOQA
File "flamingo/core/plugins/__init__.py", line 4, in <module>
from .media import Media # NOQA
File "flamingo/core/plugins/media.py", line 3, in <module>
from flamingo.core.data_model import ContentSet, Content
File "flamingo/core/data_model.py", line 4, in <module>
from textwrap import shorten
ImportError: cannot import name shorten
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /
Under debian 10.0 you can install pip3 like this:
root# apt install python3-pip
Can generate content by JSON files?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.