https://github.com/pelican-plugins/injector
Pelican plugin to inject custom code before or after specific HTML tags, without modifying your theme.
https://github.com/pelican-plugins/injector
Last synced: 8 months ago
JSON representation
Pelican plugin to inject custom code before or after specific HTML tags, without modifying your theme.
- Host: GitHub
- URL: https://github.com/pelican-plugins/injector
- Owner: pelican-plugins
- License: mit
- Created: 2023-06-23T07:21:56.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-07T16:46:46.000Z (almost 2 years ago)
- Last Synced: 2025-09-23T05:56:20.554Z (9 months ago)
- Language: Python
- Size: 20.5 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Injector: A Plugin for Pelican
[](https://github.com/pelican-plugins/injector/actions)
[](https://pypi.org/project/pelican-injector/)

Injector is a plugin for the [Pelican](https://github.com/getpelican/pelican) static site generator that allows users to inject custom code before or after specific HTML tags, without modifying your theme.
## Installation
This plugin can be installed via:
python -m pip install pelican-injector
As long as you have not explicitly added a `PLUGINS` setting to your Pelican settings file, then the newly-installed plugin should be automatically detected and enabled. Otherwise, you must add `injector` to your existing `PLUGINS` list. For more information, please see the [How to Use Plugins](https://docs.getpelican.com/en/latest/plugins.html#how-to-use-plugins) documentation.
## Settings
To configure the plugin, set the `INJECTOR_ITEMS` variable in your
Pelican settings file. This should be a list of tuples, each with two
or three elements, according to this table:
| Tuple Element | Description |
| ------ | ----------- |
| First | Name of the HTML tag where you want to inject your code |
| Second | The code you want to inject |
| Third (optional) | Specifies where to inject the code: 'before' or 'after'. If not provided, it defaults to 'after' |
```python
INJECTOR_ITEMS = [
('head', '...', 'after'),
('body', '
...', 'before'),
// add more tags and code as needed
]
```
In the following example, a script logging "Hello, world!" to the console is
injected into the `` tag of each page, and a style block is injected
before the `` tag.
```python
INJECTOR_ITEMS = [
('head', 'console.log("Hello, world!");'),
('body', '.custom-style { color: red; }', 'before'),
]
INJECTOR_IN_PAGES = True
INJECTOR_IN_ARTICLES = False
```
## Contributing
Contributions 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][].
To start contributing to this plugin, review the [Contributing to Pelican][] documentation, beginning with the **Contributing Code** section.
[existing issues]: https://github.com/pelican-plugins/injector/issues
[Contributing to Pelican]: https://docs.getpelican.com/en/latest/contribute.html
## License
This project is licensed under the [MIT license](https://opensource.org/licenses/MIT).
## Contact
If you have any questions or feedback, please open an issue on GitHub.