Skip to content

File Inclusion Shortcode Template #3799

Closed Answered by Xaldew
Xaldew asked this question in Q&A
Oct 27, 2024 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

Right, so the final(tm) plugin that also handles nesting:

#!/usr/bin/env python

"""File inclusion shortcode."""

import os.path

from nikola.plugin_categories import ShortcodePlugin


class IncludeShortcode(ShortcodePlugin):
    """Plugin for the include directive."""

    name = "include"

    def handler(self, file_name, site, post, *args, **kwargs):
        """Include the specified file in the given file."""

        dname = os.path.dirname(post.source_path)
        path = os.path.join(dname, file_name)

        with open(path, "r", encoding="utf-8") as f:
            args = {'post': post}
            output, deps = site.apply_shortcodes(f.read(), extra_context=args)
            deps.…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@Xaldew
Comment options

@Xaldew
Comment options

@Kwpolska
Comment options

@Xaldew
Comment options

Answer selected by Xaldew
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants