Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static files of drafts will be published even when DRAFT_SAVE_AS = "" #3371

Open
2 tasks done
diegoe opened this issue Jul 21, 2024 · 1 comment
Open
2 tasks done
Labels

Comments

@diegoe
Copy link

diegoe commented Jul 21, 2024

  • I have read the Filing Issues and subsequent “How to Get Help” sections of the documentation.
  • I have searched the issues (including closed ones) and believe that this is not a duplicate.
  • OS version and name: macOS 14.5 23F79
  • Python version: 3.12.4
  • Pelican version: 4.9.1
  • Link to theme: custom
  • Links to plugins: none
  • Link to your site: none
  • Link to your source: none
  • Link to a Gist with the contents of your settings file: Set DRAFT_SAVE_AS="" in default config

Issue

When an article is set to draft status, the static files used in it will be pulled into the published output even if no draft pages are generated (DRAFT_SAVE_AS="")

Since the above setting is described in docs as a way to omit entire categories/types, I would expect static files from said content to be omitted too.

@diegoe diegoe added the bug label Jul 21, 2024
@diegoe
Copy link
Author

diegoe commented Jul 21, 2024

FWIW, I have monkey-patched the above behavior with a plugin connected to article_generator_context:

"""Pelican plugin to omit publishing static_links of unrendered content.

Patches `Generator.add_static_links` to skip any content that has an
empty `.save_as`. This happens whenever content is omitted in Pelican's
configuration by setting a `*_SAVE_AS` variable to `""`
"""
import logging
import types

from pelican import signals
from pelican.contents import Content
from pelican.generators import Generator


logger = logging.getLogger(__name__)


def create_omit_draft_static(
    context_sender: Generator, metadata: dict
) -> None:
    """Patch Generator.add_static_links to omit unrendered content."""
    original_function = context_sender.add_static_links

    def patched(self: Generator, content: Content):
        if content.save_as:
            original_function(content)
        else:
            logger.info(
                "Omitting static_links for: %s",
                content.relative_source_path,
            )

    context_sender.add_static_links = types.MethodType(
        patched, context_sender
    )


def register() -> None:
    """Register Pelican plugin."""
    signals.article_generator_context.connect(create_omit_draft_static)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant