mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Fixed several errors in blog plugin
This commit is contained in:
parent
a313fa9956
commit
7099ea60a9
@ -326,7 +326,7 @@ class BlogPlugin(BasePlugin[BlogConfig]):
|
|||||||
# and must be explicitly enabled by the author.
|
# and must be explicitly enabled by the author.
|
||||||
if not isinstance(post.config.draft, bool):
|
if not isinstance(post.config.draft, bool):
|
||||||
if self.config.draft_if_future_date:
|
if self.config.draft_if_future_date:
|
||||||
return post.config.date > datetime.now()
|
return post.config.date.created > datetime.now()
|
||||||
|
|
||||||
# Post might be a draft
|
# Post might be a draft
|
||||||
return bool(post.config.draft)
|
return bool(post.config.draft)
|
||||||
@ -364,7 +364,7 @@ class BlogPlugin(BasePlugin[BlogConfig]):
|
|||||||
])
|
])
|
||||||
|
|
||||||
# Update entrypoint in navigation
|
# Update entrypoint in navigation
|
||||||
for items in [view.parent.children, nav.pages]:
|
for items in [self._resolve_siblings(view.parent, nav), nav.pages]:
|
||||||
items[items.index(page)] = view
|
items[items.index(page)] = view
|
||||||
|
|
||||||
# Return view
|
# Return view
|
||||||
@ -484,6 +484,13 @@ class BlogPlugin(BasePlugin[BlogConfig]):
|
|||||||
assert isinstance(page, View)
|
assert isinstance(page, View)
|
||||||
yield page
|
yield page
|
||||||
|
|
||||||
|
# Resolve siblings of a navigation item
|
||||||
|
def _resolve_siblings(self, item: StructureItem, nav: Navigation):
|
||||||
|
if isinstance(item, Section):
|
||||||
|
return item.children
|
||||||
|
else:
|
||||||
|
return nav.items
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
# Attach a list of pages to each other and to the given parent item without
|
# Attach a list of pages to each other and to the given parent item without
|
||||||
@ -505,7 +512,7 @@ class BlogPlugin(BasePlugin[BlogConfig]):
|
|||||||
# the top-level navigation, if no parent section was given. Note, that
|
# the top-level navigation, if no parent section was given. Note, that
|
||||||
# it's currently not possible to chose the position of a section, but
|
# it's currently not possible to chose the position of a section, but
|
||||||
# we might add support for this in the future.
|
# we might add support for this in the future.
|
||||||
items = parent.children if parent else nav.items
|
items = self._resolve_siblings(parent, nav)
|
||||||
items.append(section)
|
items.append(section)
|
||||||
|
|
||||||
# Find last sibling that is a page, skipping sections, as we need to
|
# Find last sibling that is a page, skipping sections, as we need to
|
||||||
|
@ -245,7 +245,7 @@ def _patch(config: MkDocsConfig):
|
|||||||
config.validation = copy(config.validation)
|
config.validation = copy(config.validation)
|
||||||
config.validation.links = copy(config.validation.links)
|
config.validation.links = copy(config.validation.links)
|
||||||
config.mdx_configs = copy(config.mdx_configs)
|
config.mdx_configs = copy(config.mdx_configs)
|
||||||
config.mdx_configs["toc"] = copy(config.mdx_configs["toc"])
|
config.mdx_configs["toc"] = copy(config.mdx_configs.get("toc", {}))
|
||||||
|
|
||||||
# In order to render excerpts for posts, we need to make sure that the
|
# In order to render excerpts for posts, we need to make sure that the
|
||||||
# table of contents extension is appropriately configured
|
# table of contents extension is appropriately configured
|
||||||
|
@ -60,12 +60,14 @@ class PostDate(BaseConfigOption[DateDict]):
|
|||||||
if not isinstance(config[key_name], dict):
|
if not isinstance(config[key_name], dict):
|
||||||
config[key_name] = { "created": config[key_name] }
|
config[key_name] = { "created": config[key_name] }
|
||||||
|
|
||||||
# Initialize date dictionary and convert all date values to datetime
|
# Convert all date values to datetime
|
||||||
config[key_name] = DateDict(config[key_name])
|
|
||||||
for key, value in config[key_name].items():
|
for key, value in config[key_name].items():
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
config[key_name][key] = datetime.combine(value, time())
|
config[key_name][key] = datetime.combine(value, time())
|
||||||
|
|
||||||
|
# Initialize date dictionary
|
||||||
|
config[key_name] = DateDict(config[key_name])
|
||||||
|
|
||||||
# Ensure each date value is of type datetime
|
# Ensure each date value is of type datetime
|
||||||
def run_validation(self, value: DateDict):
|
def run_validation(self, value: DateDict):
|
||||||
for key in value:
|
for key in value:
|
||||||
|
@ -326,7 +326,7 @@ class BlogPlugin(BasePlugin[BlogConfig]):
|
|||||||
# and must be explicitly enabled by the author.
|
# and must be explicitly enabled by the author.
|
||||||
if not isinstance(post.config.draft, bool):
|
if not isinstance(post.config.draft, bool):
|
||||||
if self.config.draft_if_future_date:
|
if self.config.draft_if_future_date:
|
||||||
return post.config.date > datetime.now()
|
return post.config.date.created > datetime.now()
|
||||||
|
|
||||||
# Post might be a draft
|
# Post might be a draft
|
||||||
return bool(post.config.draft)
|
return bool(post.config.draft)
|
||||||
@ -364,7 +364,7 @@ class BlogPlugin(BasePlugin[BlogConfig]):
|
|||||||
])
|
])
|
||||||
|
|
||||||
# Update entrypoint in navigation
|
# Update entrypoint in navigation
|
||||||
for items in [view.parent.children, nav.pages]:
|
for items in [self._resolve_siblings(view.parent, nav), nav.pages]:
|
||||||
items[items.index(page)] = view
|
items[items.index(page)] = view
|
||||||
|
|
||||||
# Return view
|
# Return view
|
||||||
@ -484,6 +484,13 @@ class BlogPlugin(BasePlugin[BlogConfig]):
|
|||||||
assert isinstance(page, View)
|
assert isinstance(page, View)
|
||||||
yield page
|
yield page
|
||||||
|
|
||||||
|
# Resolve siblings of a navigation item
|
||||||
|
def _resolve_siblings(self, item: StructureItem, nav: Navigation):
|
||||||
|
if isinstance(item, Section):
|
||||||
|
return item.children
|
||||||
|
else:
|
||||||
|
return nav.items
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
# Attach a list of pages to each other and to the given parent item without
|
# Attach a list of pages to each other and to the given parent item without
|
||||||
@ -505,7 +512,7 @@ class BlogPlugin(BasePlugin[BlogConfig]):
|
|||||||
# the top-level navigation, if no parent section was given. Note, that
|
# the top-level navigation, if no parent section was given. Note, that
|
||||||
# it's currently not possible to chose the position of a section, but
|
# it's currently not possible to chose the position of a section, but
|
||||||
# we might add support for this in the future.
|
# we might add support for this in the future.
|
||||||
items = parent.children if parent else nav.items
|
items = self._resolve_siblings(parent, nav)
|
||||||
items.append(section)
|
items.append(section)
|
||||||
|
|
||||||
# Find last sibling that is a page, skipping sections, as we need to
|
# Find last sibling that is a page, skipping sections, as we need to
|
||||||
|
@ -245,7 +245,7 @@ def _patch(config: MkDocsConfig):
|
|||||||
config.validation = copy(config.validation)
|
config.validation = copy(config.validation)
|
||||||
config.validation.links = copy(config.validation.links)
|
config.validation.links = copy(config.validation.links)
|
||||||
config.mdx_configs = copy(config.mdx_configs)
|
config.mdx_configs = copy(config.mdx_configs)
|
||||||
config.mdx_configs["toc"] = copy(config.mdx_configs["toc"])
|
config.mdx_configs["toc"] = copy(config.mdx_configs.get("toc", {}))
|
||||||
|
|
||||||
# In order to render excerpts for posts, we need to make sure that the
|
# In order to render excerpts for posts, we need to make sure that the
|
||||||
# table of contents extension is appropriately configured
|
# table of contents extension is appropriately configured
|
||||||
|
@ -60,12 +60,14 @@ class PostDate(BaseConfigOption[DateDict]):
|
|||||||
if not isinstance(config[key_name], dict):
|
if not isinstance(config[key_name], dict):
|
||||||
config[key_name] = { "created": config[key_name] }
|
config[key_name] = { "created": config[key_name] }
|
||||||
|
|
||||||
# Initialize date dictionary and convert all date values to datetime
|
# Convert all date values to datetime
|
||||||
config[key_name] = DateDict(config[key_name])
|
|
||||||
for key, value in config[key_name].items():
|
for key, value in config[key_name].items():
|
||||||
if isinstance(value, date):
|
if isinstance(value, date):
|
||||||
config[key_name][key] = datetime.combine(value, time())
|
config[key_name][key] = datetime.combine(value, time())
|
||||||
|
|
||||||
|
# Initialize date dictionary
|
||||||
|
config[key_name] = DateDict(config[key_name])
|
||||||
|
|
||||||
# Ensure each date value is of type datetime
|
# Ensure each date value is of type datetime
|
||||||
def run_validation(self, value: DateDict):
|
def run_validation(self, value: DateDict):
|
||||||
for key in value:
|
for key in value:
|
||||||
|
Loading…
Reference in New Issue
Block a user