Skip to content

Commit

Permalink
Added missing enabled setting for tags plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Apr 22, 2023
1 parent c0cdb3c commit ba90cb1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
20 changes: 19 additions & 1 deletion material/plugins/tags/plugin.py
Expand Up @@ -19,7 +19,6 @@
# IN THE SOFTWARE.

import logging
import os
import sys

from collections import defaultdict
Expand All @@ -36,6 +35,9 @@

# Tags plugin configuration scheme
class TagsPluginConfig(Config):
enabled = opt.Type(bool, default = True)

# Options for tags
tags_file = opt.Optional(opt.Type(str))

# -----------------------------------------------------------------------------
Expand All @@ -46,6 +48,10 @@ class TagsPlugin(BasePlugin[TagsPluginConfig]):

# Initialize plugin
def on_config(self, config):
if not self.config.enabled:
return

# Initialize tags
self.tags = defaultdict(list)
self.tags_file = None

Expand All @@ -64,12 +70,20 @@ def on_config(self, config):

# Hack: 2nd pass for tags index page(s)
def on_nav(self, nav, config, files):
if not self.config.enabled:
return

# Resolve tags index page
file = self.config.tags_file
if file:
self.tags_file = self._get_tags_file(files, file)

# Build and render tags index page
def on_page_markdown(self, markdown, page, config, files):
if not self.config.enabled:
return

# Render tags index page
if page.file == self.tags_file:
return self._render_tag_index(markdown)

Expand All @@ -79,6 +93,10 @@ def on_page_markdown(self, markdown, page, config, files):

# Inject tags into page (after search and before minification)
def on_page_context(self, context, page, config, nav):
if not self.config.enabled:
return

# Provide tags for page
if "tags" in page.meta:
context["tags"] = [
self._render_tag(tag)
Expand Down
20 changes: 19 additions & 1 deletion src/plugins/tags/plugin.py
Expand Up @@ -19,7 +19,6 @@
# IN THE SOFTWARE.

import logging
import os
import sys

from collections import defaultdict
Expand All @@ -36,6 +35,9 @@

# Tags plugin configuration scheme
class TagsPluginConfig(Config):
enabled = opt.Type(bool, default = True)

# Options for tags
tags_file = opt.Optional(opt.Type(str))

# -----------------------------------------------------------------------------
Expand All @@ -46,6 +48,10 @@ class TagsPlugin(BasePlugin[TagsPluginConfig]):

# Initialize plugin
def on_config(self, config):
if not self.config.enabled:
return

# Initialize tags
self.tags = defaultdict(list)
self.tags_file = None

Expand All @@ -64,12 +70,20 @@ def on_config(self, config):

# Hack: 2nd pass for tags index page(s)
def on_nav(self, nav, config, files):
if not self.config.enabled:
return

# Resolve tags index page
file = self.config.tags_file
if file:
self.tags_file = self._get_tags_file(files, file)

# Build and render tags index page
def on_page_markdown(self, markdown, page, config, files):
if not self.config.enabled:
return

# Render tags index page
if page.file == self.tags_file:
return self._render_tag_index(markdown)

Expand All @@ -79,6 +93,10 @@ def on_page_markdown(self, markdown, page, config, files):

# Inject tags into page (after search and before minification)
def on_page_context(self, context, page, config, nav):
if not self.config.enabled:
return

# Provide tags for page
if "tags" in page.meta:
context["tags"] = [
self._render_tag(tag)
Expand Down

0 comments on commit ba90cb1

Please sign in to comment.