mkdocs-encryptcontent-plugin icon indicating copy to clipboard operation
mkdocs-encryptcontent-plugin copied to clipboard

Compatibility Issue with Blog Plugin in Mkdocs-Material: Encrypted Content Excerpts Exposed on Blog Index Page

Open lnw143 opened this issue 4 months ago • 3 comments

Problem Description

I am using the encryptcontent plugin to protect specific pages in my MkDocs site. The plugin works correctly when navigating to an encrypted page directly, as it prompts for a password. However, I am also using the built-in blog plugin in mkdocs-material to create a blog-style index page, and it exposes excerpts of the encrypted posts on this homepage, completely bypassing the encryption.

Steps to Reproduce

  1. Set up an MkDocs project with both mkdocs-material's built-in blog plugin and mkdocs-encryptcontent-plugin.
  2. Create a post with encryptcontent metadata (e.g., level: secret).
  3. Build the site and serve it. (mkdocs serve)
  4. Observe the blog index page (homepage). The excerpt/content from the encrypted post will be visible without any password prompt.
  5. Click the "Read more" link for that same post. You will be correctly prompted for a password, and the full content is encrypted.

Expected Behavior

Encrypted posts should not reveal their content in any form on listing pages (like the blog index) generated by other plugins. The expected behavior could be implemented in one of two ways:

  1. Preferred: The plugin should intercept the content processing for listings and replace the content of encrypted pages with a placeholder (e.g., "This post is encrypted" or a custom message).
  2. Alternative: Provide a configuration option (e.g., summary_placeholder: "This content is protected.") to allow users to define what text is shown in place of encrypted content on summary pages.

Environment

  • Python 3.13.5
  • mkdocs-encryptcontent-plugin 3.0.5
  • mkdocs 1.6.1
  • mkdocs-material 9.6.15

Configuration Example (mkdocs.yml)

theme:
  name: material
  language: 'zh'
  custom_dir: overrides
plugins:
  - search
  - encryptcontent:
      password_inventory:
      title_prefix: '[Protected]'
      summary: 'This passage is protected by password.'
      decryption_failure_message: 'Invalid user name or password.'
      password_button: True
      password_button_text: 'Enter'
      placeholder_user: 'User'
      placeholderplaceholder: 'Password'
      password_file: 'passwords.yml'
      remember_keys: false
      remember_password: false  
      threshold_warning_min_entropy: 100
      search_index: 'dynamically'
      encrypted_something:
        md-sidebar__inner: [div, class]
  - toggle-sidebar:
      toggle_button: navigation
  - blog:
      post_slugify: !!python/object/apply:pymdownx.slugs.slugify
        kwds:
          case: lower
      blog_dir: "./"
      post_url_format: "{categories}/{file}"
      post_date_format: medium
      post_url_max_categories: 1
      blog_toc: true

Thank you for developing and maintaining this essential plugin. I would be happy to provide more details or assist in testing any potential fixes.

lnw143 avatar Aug 25 '25 04:08 lnw143

Try injecting the template with this configuration: https://unverbuggt.github.io/mkdocs-encryptcontent-plugin/features/modifypages/#inject-decrypt-formtpl-to-theme

But a user changed it like this recently: https://github.com/unverbuggt/mkdocs-encryptcontent-plugin/issues/82#issuecomment-3027769531

unverbuggt avatar Aug 30 '25 19:08 unverbuggt

I'm sorry to trouble you but it seems that these methods still didn't work, you can find a example at https://lnw143.github.io/blog/, where the encrypted post is https://lnw143.github.io/blog/record/2025-08/ and it is showed at the Index Page.

here is the whole mkdocs.yml

# Project information
site_name: Liam's Blog
site_author: lnw143
site_url: https://lnw143.github.io/blog/

# Repository
repo_name: 'blog'
repo_url: 'https://github.com/lnw143/blog'
edit_uri: 'edit/main/docs/'

# Theme Settings
theme:
  name: material
  language: 'zh'
  custom_dir: overrides
  palette:
    # Palette toggle for light mode
    - media: "(prefers-color-scheme: light)"
      scheme: default
      primary: white
      accent: red
      toggle:
        icon: material/toggle-switch
        name: Switch to dark mode

    # Palette toggle for dark mode
    - media: "(prefers-color-scheme: dark)"
      scheme: slate
      primary: custom
      accent: white
      toggle:
        icon: material/toggle-switch-off-outline
        name: Switch to light mode
  favicon: 'favicon.svg'
  icon:
    logo: 'material/omega'
  font:
    text: 'Fira Sans'
    code: 'Fira Mono'
  features:
    - content.code.annotate
    - content.code.select
    - content.code.copy
    - navigation.tabs
    - navigation.instant
    - navigation.indexes

# Contents
nav:
  # something else

# Plugins
plugins:
  - search
  - encryptcontent:
      password_inventory:
      title_prefix: '[Protected]'
      summary: 'This passage is protected by password.'
      decryption_failure_message: 'Invalid user name or password.'
      password_button: True
      password_button_text: 'Enter'
      placeholder_user: 'User'
      placeholderplaceholder: 'Password'
      password_file: 'passwords.yml'
      remember_keys: false
      remember_password: false  
      threshold_warning_min_entropy: 100
      search_index: 'dynamically'
      encrypted_something:
        md-sidebar__inner: [div, class]
      # inject:
      #   md-post: [article, class]
  - toggle-sidebar:
      toggle_button: navigation
  - blog:
      post_slugify: !!python/object/apply:pymdownx.slugs.slugify
        kwds:
          case: lower
      blog_dir: "./"
      post_url_format: "{categories}/{file}"
      post_date_format: medium
      post_url_max_categories: 1
      blog_toc: true

# Extensions
markdown_extensions:
  - admonition
  - def_list
  - footnotes
  - meta
  - attr_list
  - md_in_html
  - markdown.extensions.toc:
      slugify: !!python/object/apply:pymdownx.slugs.slugify
        kwds:
          case: lower
  - pymdownx.emoji:
      emoji_index: !!python/name:material.extensions.emoji.twemoji
      emoji_generator: !!python/name:materialx.emoji.to_svg
      # emoji_generator: !!python/name:pymdownx.emoji.to_svg
  - toc:
      permalink: ""
      slugify: !!python/object/apply:pymdownx.slugs.slugify {}
  - pymdownx.arithmatex:
      generic: true
  - pymdownx.caret
  - pymdownx.critic
  - pymdownx.details
  - pymdownx.inlinehilite
  - pymdownx.keys
  - pymdownx.magiclink
  - pymdownx.mark
  - pymdownx.snippets:
      check_paths: true
  - pymdownx.progressbar
  - pymdownx.smartsymbols
  - pymdownx.superfences
  - pymdownx.highlight:
      linenums: true
      line_spans: __span
      pygments_lang_class: true
  - pymdownx.tasklist:
      custom_checkbox: true
  - pymdownx.tilde
  - pymdownx.tabbed:
      alternate_style: true

extra_javascript:
  - javascripts/katex.js
  - https://unpkg.com/katex@0/dist/katex.min.js
  - https://unpkg.com/katex@0/dist/contrib/auto-render.min.js
  - https://unpkg.com/[email protected]/dist/jquery.js
  - https://cdnjs.cloudflare.com/ajax/libs/aplayer/1.10.1/APlayer.min.js
  - https://cdn.jsdelivr.net/npm/[email protected]/dist/Meting.min.js

extra_css:
  - https://unpkg.com/katex@0/dist/katex.min.css
  - stylesheets/extra.css
  - https://cdnjs.cloudflare.com/ajax/libs/aplayer/1.10.1/APlayer.min.css

lnw143 avatar Sep 03 '25 04:09 lnw143

I'm not really familiar with blog plugin. So your problem is that some blog posts should be encrypted and some shouldn't? And when they are encrypted they still show up on the front page?

Try using excerpts in your blog posts to hide the content from the front page: https://squidfunk.github.io/mkdocs-material/plugins/blog/#config.post_excerpt-required https://squidfunk.github.io/mkdocs-material/plugins/blog/#config.post_excerpt_separator

The problem is that the front page of the blog plugin is not a configurable markdown page (at least that's what I see without looking any further) and so we cannot use the encryptcontent plugin there.

unverbuggt avatar Sep 04 '25 17:09 unverbuggt