简体   繁体   中英

Pelican - How can I render html pages instead of markup?

I'm redoing my Flask site in Pelican as I intend to start blogging. I have html files already for some specific pages (ie contact, books, etc) that use bootstrap cards and other features that are not possible in markdown (as far as I know).

How can I render these in the build cycle. There has to be a config variable for that? I found TEMPLATE_PAGES but it didn't seem to work. This has to be possible, right?

from their official documentation

http://docs.getpelican.com/en/stable/content.html#writing-content

Pelican can also process HTML files ending in .html and .htm. Pelican interprets the HTML in a very straightforward manner, reading metadata from meta tags, the title from the title tag, and the body out from the body tag:

I was trying to do the same thing as you and finally found the relevant documentation ( you can find it here where it defines the variable DIRECT_TEMPLATES ):

DIRECT_TEMPLATES = ['index', 'categories', 'authors', 'archives']

List of templates that are used directly to render content. Typically direct templates are used to generate index pages for collections of content (eg, tags and category index pages). If the tag and category collections are not needed, set DIRECT_TEMPLATES = ['index', 'archives']

For example, let's say you have a file my_file.html in your templates directory. If you want to render it like other templates files in your theme instead of using only Markdown, you could append an item to the list in the variable DIRECT_TEMPLATES that you will have to define in your configuration file (it is pelicanconf.py by default). The result should look similar to this:

DIRECT_TEMPLATES = [
    'index', 'categories', 'authors', 'archives',  # (default)
    'my_file'  # other HTML template to render
]

By proceeding this way, my_file.html would be rendered as any other HTML file with Jinja2 syntax and all the good stuff you want to use.

I know this comes late but hopefully someone (maybe still you!) will benefit from this answer. It is definitely a very well hidden feature for sure...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM