Coder Social home page Coder Social logo

injector's Introduction

Injector: A Plugin for Pelican

Build Status PyPI Version License

Injector is a plugin for the 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 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'
INJECTOR_ITEMS = [
    ('head', '<script>...</script>', 'after'),
    ('body', '<div>...</div>', 'before'),
    // add more tags and code as needed
]

In the following example, a script logging "Hello, world!" to the console is injected into the <head> tag of each page, and a style block is injected before the <body> tag.

INJECTOR_ITEMS = [
    ('head', '<script>console.log("Hello, world!");</script>'),
    ('body', '<style>.custom-style { color: red; }</style>', '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.

License

This project is licensed under the MIT license.

Contact

If you have any questions or feedback, please open an issue on GitHub.

injector's People

Contributors

botpub avatar buanzo avatar justinmayer avatar pre-commit-ci[bot] avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

injector's Issues

Add support for top-level tags like head

My initial implementation failed to inject code for outside-article tags, so I have devised this idea:

Currently, the inject_content() function is trying to insert custom code into the HTML content of articles and pages, which works great if the specified tags are found in the content. However, if a tag is not found in the content (which may be the case for tags that are part of the theme template, such as ), the injection fails as the tag is not found.

To handle these cases, we could make inject_content() keep track of failed injections and return a list of them. Then, we could connect a new function to the content_written signal, which is triggered after an article or page has been written to disk, and perform the injection at that time.

Publish package to PyPI

Hey @buanzo. Nice work on the follow-up changes to the Injector plugin. Following are some things I noticed upon returning to my desk and reviewing the recent developments:

  • #1 was merged before it was fully ready. When you see commits prefixed by fixup! [โ€ฆ], those are intended to be squashed into their parent commits before the PR is merged. So what I was looking for in that case was a PR review and approval, after which I would have squashed the commits and merged the PR. Not a big deal, of course. Just something to keep in mind for the future in order to keep commit history somewhat organized and tidy.
  • There is (another) copy+paste fail in the badge links in the README.
  • The contents of #1 were manually tagged with 1.0.0 and a GitHub release was added manually, whereas these steps are usually handled automatically in CI via AutoPub and GitHub Actions.

Regarding fixing the latter two issues, I'd like to do the following:

  • Fix the README badge links.
  • Remove the 1.0.0 tag and GitHub release.
  • Use AutoPub to publish the contents of current main as 1.0.0 on GitHub and PyPI.

Any objections if I go ahead and take these remedial actions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.