mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
MkDocs upgrade: refactor path handling
This commit is contained in:
parent
02bcffa6a8
commit
c383892aae
@ -56,7 +56,7 @@ class SearchIndex(BaseIndex):
|
||||
else:
|
||||
log.warning(
|
||||
"Skipping 'tags' due to invalid syntax [%s]: %s",
|
||||
page.file.src_path,
|
||||
page.file.src_uri,
|
||||
page.meta["tags"]
|
||||
)
|
||||
|
||||
|
@ -31,6 +31,7 @@ from mkdocs.commands.build import DuplicateFilter
|
||||
from mkdocs.config.base import Config
|
||||
from mkdocs.config import config_options as opt
|
||||
from mkdocs.plugins import BasePlugin
|
||||
import posixpath
|
||||
from shutil import copyfile
|
||||
from tempfile import TemporaryFile
|
||||
from zipfile import ZipFile
|
||||
@ -245,7 +246,7 @@ class SocialPlugin(BasePlugin[SocialPluginConfig]):
|
||||
# Generate meta tags
|
||||
def _generate_meta(self, page, config):
|
||||
directory = self.config.cards_dir
|
||||
file, _ = os.path.splitext(page.file.src_path)
|
||||
file, _ = os.path.splitext(page.file.src_uri)
|
||||
|
||||
# Compute page title
|
||||
title = page.meta.get("title", page.title)
|
||||
@ -258,7 +259,7 @@ class SocialPlugin(BasePlugin[SocialPluginConfig]):
|
||||
description = page.meta["description"]
|
||||
|
||||
# Resolve image URL
|
||||
url = "{}.png".format(os.path.join(
|
||||
url = "{}.png".format(posixpath.join(
|
||||
config.site_url,
|
||||
directory,
|
||||
file
|
||||
|
@ -121,11 +121,9 @@ class TagsPlugin(BasePlugin[TagsPluginConfig]):
|
||||
content = [f"## <span class=\"{classes}\">{tag}</span>", ""]
|
||||
for page in pages:
|
||||
|
||||
# Ensure forward slashes, as we have to use the path of the source
|
||||
# file which contains the operating system's path separator.
|
||||
url = utils.get_relative_url(
|
||||
page.file.src_path.replace(os.path.sep, "/"),
|
||||
self.tags_file.src_path.replace(os.path.sep, "/")
|
||||
page.file.src_uri,
|
||||
self.tags_file.src_uri
|
||||
)
|
||||
|
||||
# Render link to page
|
||||
|
@ -56,7 +56,7 @@ class SearchIndex(BaseIndex):
|
||||
else:
|
||||
log.warning(
|
||||
"Skipping 'tags' due to invalid syntax [%s]: %s",
|
||||
page.file.src_path,
|
||||
page.file.src_uri,
|
||||
page.meta["tags"]
|
||||
)
|
||||
|
||||
|
@ -31,6 +31,7 @@ from mkdocs.commands.build import DuplicateFilter
|
||||
from mkdocs.config.base import Config
|
||||
from mkdocs.config import config_options as opt
|
||||
from mkdocs.plugins import BasePlugin
|
||||
import posixpath
|
||||
from shutil import copyfile
|
||||
from tempfile import TemporaryFile
|
||||
from zipfile import ZipFile
|
||||
@ -245,7 +246,7 @@ class SocialPlugin(BasePlugin[SocialPluginConfig]):
|
||||
# Generate meta tags
|
||||
def _generate_meta(self, page, config):
|
||||
directory = self.config.cards_dir
|
||||
file, _ = os.path.splitext(page.file.src_path)
|
||||
file, _ = os.path.splitext(page.file.src_uri)
|
||||
|
||||
# Compute page title
|
||||
title = page.meta.get("title", page.title)
|
||||
@ -258,7 +259,7 @@ class SocialPlugin(BasePlugin[SocialPluginConfig]):
|
||||
description = page.meta["description"]
|
||||
|
||||
# Resolve image URL
|
||||
url = "{}.png".format(os.path.join(
|
||||
url = "{}.png".format(posixpath.join(
|
||||
config.site_url,
|
||||
directory,
|
||||
file
|
||||
|
@ -121,11 +121,9 @@ class TagsPlugin(BasePlugin[TagsPluginConfig]):
|
||||
content = [f"## <span class=\"{classes}\">{tag}</span>", ""]
|
||||
for page in pages:
|
||||
|
||||
# Ensure forward slashes, as we have to use the path of the source
|
||||
# file which contains the operating system's path separator.
|
||||
url = utils.get_relative_url(
|
||||
page.file.src_path.replace(os.path.sep, "/"),
|
||||
self.tags_file.src_path.replace(os.path.sep, "/")
|
||||
page.file.src_uri,
|
||||
self.tags_file.src_uri
|
||||
)
|
||||
|
||||
# Render link to page
|
||||
|
Loading…
Reference in New Issue
Block a user