dynamic content

This commit is contained in:
randogoth 2023-05-23 21:32:01 +03:00
parent eb8fdb1a46
commit 651becfb6b
4 changed files with 47 additions and 1 deletions

View file

@ -102,3 +102,24 @@ If you want the same settings to be honoured by the templates, they need to be i
```jinja ```jinja
{{ MICRON_LINK_FORMAT[0] }}`[{{ p.title }}`:/{{ p.url }}]{{ MICRON_LINK_FORMAT[1] }} {{ MICRON_LINK_FORMAT[0] }}`[{{ p.title }}`:/{{ p.url }}]{{ MICRON_LINK_FORMAT[1] }}
``` ```
## Dynamic Content
If you want to place an executable script file in the output folder, use Pelican's `STATIC_PATHS`
setting to mark it as a static file and the `EXTRA_PATH_METADATA` setting to copy it to
the output folder.
```python
STATIC_PATHS = ['../scripts/helloworld.mu']
EXTRA_PATH_METADATA = {'../scripts/helloworld.mu': {'path': 'micron/helloworld.mu'},}
```
A good way to link to such a dynamic content file is to add a dummy article or page with an
empty `save_as` meta tag and a `url` tag pointing to the script's final location.
```
Title: Hello World
Date: 2023-05-22
save_as:
url: helloworld.mu
```
(see the `pelicanconf.py `and `script.md` files in the examples folder.)

20
example/content/script.md Normal file
View file

@ -0,0 +1,20 @@
Title: Hello World
Date: 2023-05-22
save_as:
url: helloworld.mu
<!--
The empty 'save_as' tag tells Pelican to not save this file
but use the given 'url' in all links that point to this
dummy article. We only use this to create links throughout
the generated page.
The following settings in 'pelicanconf.py' will then copy the
'helloworld.mu' script from the 'scripts' folder to where this
'url' points.
STATIC_PATHS = ['../scripts/helloworld.mu']
EXTRA_PATH_METADATA = {'../scripts/helloworld.mu': {'path': '/micron/helloworld.mu'},}
-->

View file

@ -25,3 +25,5 @@ PLUGIN_PATHS = ["../plugin"]
PLUGINS = ['micron'] PLUGINS = ['micron']
THEME = '../theme' THEME = '../theme'
MICRON_PATH = 'output/micron' MICRON_PATH = 'output/micron'
STATIC_PATHS = ['../scripts/helloworld.mu']
EXTRA_PATH_METADATA = {'../scripts/helloworld.mu': {'path': 'micron/helloworld.mu'},}

3
example/scripts/helloworld.mu Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/python3
print('Hello World')