getpelican / pelican-plugins

Collection of plugins for the Pelican static site generator
Other
1.39k stars 856 forks source link

[New Plugin] Pelican-Injector: A plugin to inject code into specific HTML tags in pages and articles #1389

Closed buanzo closed 1 year ago

buanzo commented 1 year ago

I would like to propose a new plugin: Pelican-Injector.

Functionality: Pelican-Injector is designed to allow users to inject custom code (like scripts or styles) into specific HTML tags of their Pelican-generated pages and articles. This plugin can be beneficial for users who need to customize their HTML output further, such as injecting analytics scripts or additional styles.

The plugin makes use of the 'article_generator_write_article' and 'page_generator_write_page' signals to insert the specified code into the final HTML of each page and article.

Users can specify the tag into which the code should be injected, the code to inject, and whether to inject before or after the specified tag, through settings in their Pelican configuration file. They can also control whether injection should occur in pages, articles, or both.

Sample Configuration:

INJECTOR_CONFIG = [
    ('head', '<script>console.log("Hello, world!");</script>'),
    ('body', '<style>.custom-style { color: red; }</style>', 'before'),
]
INJECT_INTO_PAGES = True
INJECT_INTO_ARTICLES = False

In the given configuration 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. It could also be used to easily add Google Analytics scripts, without having to use a theme designed for such a use case.

I believe this plugin would be a valuable addition to the Pelican ecosystem and look forward to feedback and suggestions.

You can find the plugin here: Pelican-Injector

justinmayer commented 1 year ago

Hi Arturo. Thank you for reaching out. As of a few years ago, we have been encouraging folks to host repositories under the new Pelican Plugins organization. This serves to increase visibility as well as facilitate collaboration between Pelican maintainers and plugin authors such as yourself. The end result is a more vibrant and well-maintained plugin ecosystem for Pelican users.

What do you think? Would you be amenable to having the Injector plugin located under the Pelican Plugins organization?

buanzo commented 1 year ago

Hi Justin! Absolutely. In fact, I thought I was opening the issue in the right place to do just that.

I will follow your indications. Thank you!

PS: I am thrilled to contribute to Pelican.

On Mon, Jun 19, 2023, 07:59 Justin Mayer @.***> wrote:

Hi Arturo. Thank you for reaching out. As of a few years ago, we have been encouraging folks to host repositories under the new Pelican Plugins https://github.com/pelican-plugins organization. This serves to increase visibility as well as facilitate collaboration between Pelican maintainers and plugin authors such as yourself. The end result is a more vibrant and well-maintained plugin ecosystem for Pelican users.

What do you think? Would you be amenable to having the Injector plugin located under the Pelican Plugins https://github.com/pelican-plugins organization?

— Reply to this email directly, view it on GitHub https://github.com/getpelican/pelican-plugins/issues/1389#issuecomment-1597054959, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEHBT2KSS576TEKJCQ5K6TXMA5KZANCNFSM6AAAAAAZLZWTOQ . You are receiving this because you authored the thread.Message ID: @.***>

buanzo commented 1 year ago

Let me know if there's anything I must do.

justinmayer commented 1 year ago

Hi Arturo. You did indeed open the issue in the right place. I just wanted to make sure we were on the same page. Seems like we are! 😁

I took the liberty of creating the new plugin repository and importing your commits. Then I migrated the plugin structure to the namespace format so it can be Pip-installed, as well as a number of other changes that I think would be beneficial to the project.

Let's move this discussion to the new repo. Would you please take a look and post any comments as a review on this pull request? https://github.com/pelican-plugins/injector/pull/1