{"id":13696141,"url":"https://github.com/pelican-plugins/jinja2content","last_synced_at":"2025-04-10T04:32:46.835Z","repository":{"id":44664848,"uuid":"242495457","full_name":"pelican-plugins/jinja2content","owner":"pelican-plugins","description":"Use Jinja2 template code within post content","archived":false,"fork":false,"pushed_at":"2024-04-01T22:49:59.000Z","size":37,"stargazers_count":18,"open_issues_count":3,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-14T12:30:35.061Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pelican-plugins.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"justinmayer","custom":"https://donate.getpelican.com","liberapay":"pelican"}},"created_at":"2020-02-23T10:15:17.000Z","updated_at":"2024-04-14T12:30:35.062Z","dependencies_parsed_at":"2024-04-13T00:41:04.659Z","dependency_job_id":"150134b1-c3cd-4474-b70d-4b9aaa897453","html_url":"https://github.com/pelican-plugins/jinja2content","commit_stats":{"total_commits":40,"total_committers":7,"mean_commits":5.714285714285714,"dds":0.25,"last_synced_commit":"fbb49bef84ebb852608ac833305c9c9de210fa3f"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pelican-plugins%2Fjinja2content","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pelican-plugins%2Fjinja2content/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pelican-plugins%2Fjinja2content/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pelican-plugins%2Fjinja2content/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pelican-plugins","download_url":"https://codeload.github.com/pelican-plugins/jinja2content/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248049709,"owners_count":21039265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T18:00:36.611Z","updated_at":"2025-04-10T04:32:46.465Z","avatar_url":"https://github.com/pelican-plugins.png","language":"Python","funding_links":["https://github.com/sponsors/justinmayer","https://donate.getpelican.com","https://liberapay.com/pelican"],"categories":["Plugins"],"sub_categories":["Migrated to new architecture"],"readme":"# Jinja2Content Plugin for Pelican\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/pelican-plugins/jinja2content/main.yml?branch=main)](https://github.com/pelican-plugins/jinja2content/actions) [![PyPI Version](https://img.shields.io/pypi/v/pelican-jinja2content)](https://pypi.org/project/pelican-jinja2content/)\n\nThis plugin allows the use of Jinja2 directives inside your Pelican articles and pages.\n\nIn this approach, your content is *first* rendered by the Jinja template engine. The result is then passed to the normal Pelican reader as usual. There are two consequences for usage. First, this means the Pelican context and Jinja variables [usually visible](https://docs.getpelican.com/en/stable/themes.html#templates-and-variables) to your article or page template are _not_ available at rendering time. Second, it means that if any of your input content could be parsed as Jinja directives, they will be rendered as such. This is unlikely to happen accidentally, but it’s good to be aware of.\n\nAll input that needs Pelican variables such as `article`, `category`, etc., should be put inside your *theme’s* templating. As such, the main use of this plugin is to automatically generate parts of your articles or pages.\n\nMarkdown, reStructured Text, and HTML input are all supported. Note that by enabling this plugin, all input files of these file types will be pre-processed with the Jinja renderer. It is not currently supported to selectively enable or disable `jinja2content` for only some of these input sources.\n\n\nExample\n-------\n\nOne usage is to embed repetitive HTML in Markdown articles. Since Markdown doesn’t allow customization of layout, if anything more sophisticated than just displaying an image is necessary, one is forced to embed HTML in Markdown articles (i.e. hard-code `\u003cdiv\u003e` tags and then select them from the theme’s CSS). However, with `jinja2content`, one can do the following:\n\nFile `my-cool-article.md`\n```\n# My cool title\n\nMy cool content.\n\n{% from 'img_desc.html' import img_desc %}\n{{ img_desc(\"/images/my-cool-image.png\",\n    \"This is a cool tooltip\",\n    \"This is a very cool image.\") }}\n```\n\nWhere file `img_desc.html` contains:\n```\n{% macro img_desc(src, title='', desc='') -%}\n\u003cdiv class=\"img-desc\"\u003e\n  \u003cp\u003e\u003cimg src=\"{{ src }}\" title=\"{{ title }}\"\u003e\u003c/p\u003e\n  {% if desc %}\n  \u003cp\u003e\u003cem\u003e{{ desc }}\u003c/em\u003e\u003c/p\u003e\n  {% endif %}\n\u003c/div\u003e\n{%- endmacro %}\n```\n\nThe result will be:\n```\n# My cool title\n\nMy cool content.\n\n\u003cdiv class=\"img-desc\"\u003e\n  \u003cp\u003e\u003cimg src=\"/images/my-cool-image.png\" title=\"This is a cool tooltip\"\u003e\u003c/p\u003e\n  \u003cp\u003e\u003cem\u003eThis is a very cool image.\u003c/em\u003e\u003c/p\u003e\n\u003c/div\u003e\n```\n\nAfter this, the Markdown will be rendered into HTML and only then the theme’s templates will be applied.\n\nIn this way, Markdown articles have more control over the content that is passed to the theme’s `article.html` template, without the need to pollute the Markdown with HTML. Another added benefit is that now `img_desc` is reusable across articles.\n\nNote that templates rendered with `jinja2content` can contain Markdown as well as HTML, since they are added before the Markdown content is converted to HTML.\n\n\nInstallation\n------------\n\nThis plugin can be installed via:\n\n    pip install pelican-jinja2content\n\n\nConfiguration\n-------------\n\nThis plugin accepts the setting `JINJA2CONTENT_TEMPLATES` which should be set to a list of paths relative to `PATH` (the main content directory, usually `\"content\"`). `jinja2content` will look for templates inside these directories, in order. If they are not found in any, the theme’s templates folder is used.\n\n\nExtending\n---------\n\nThis plugin is structured such that it should be quite easy to extend readers for other file types to also render Jinja template logic. It should be sufficient to create a new reader class that inherits from the `JinjaContentMixin` and then your desired reader class. See class definitions in the source for examples.\n\n\nContributing\n------------\n\nContributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting on [existing issues][].\n\nTo start contributing to this plugin, review the [Contributing to Pelican][] documentation, beginning with the **Contributing Code** section.\n\n\nAcknowledgements\n----------------\n\n- Original implementation by @joachimneu and re-worked by @Leonardo.\n- Updated to support reST and HTML input by @micahjsmith.\n- Converted to new plugin format by @justinmayer.\n- Replaces [pelican-jinja2content](https://github.com/joachimneu/pelican-jinja2content/tree/f73ef9b1ef1ee1f56c80757b4190b53f8cd607d1), which had become unmaintained.\n\n\n[existing issues]: https://github.com/pelican-plugins/jinja2content/issues\n[Contributing to Pelican]: https://docs.getpelican.com/en/latest/contribute.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpelican-plugins%2Fjinja2content","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpelican-plugins%2Fjinja2content","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpelican-plugins%2Fjinja2content/lists"}