Make naming a bit more clear
This commit is contained in:
parent
30670d998e
commit
bd55a6b66f
|
@ -9,8 +9,8 @@ from pelican.utils import pelican_open
|
||||||
|
|
||||||
from markdown import Markdown
|
from markdown import Markdown
|
||||||
|
|
||||||
ARTICLES = {}
|
ARTICLE_PATHS = {}
|
||||||
FILES = {}
|
FILE_PATHS = {}
|
||||||
|
|
||||||
link = r'\[\[\s*(?P<filename>[\w+\s.]+)(\|\s*(?P<linkname>[\w\s]+))?\]\]'
|
link = r'\[\[\s*(?P<filename>[\w+\s.]+)(\|\s*(?P<linkname>[\w\s]+))?\]\]'
|
||||||
file_re = re.compile(r'!' + link)
|
file_re = re.compile(r'!' + link)
|
||||||
|
@ -47,7 +47,7 @@ class ObsidianMarkdownReader(MarkdownReader):
|
||||||
def replace_obsidian_links(self, text):
|
def replace_obsidian_links(self, text):
|
||||||
def link_replacement(match):
|
def link_replacement(match):
|
||||||
filename, linkname = get_file_and_linkname(match)
|
filename, linkname = get_file_and_linkname(match)
|
||||||
path = ARTICLES.get(filename)
|
path = ARTICLE_PATHS.get(filename)
|
||||||
if path:
|
if path:
|
||||||
link_structure = '[{linkname}]({{filename}}/{path}/{filename}.md)'.format(
|
link_structure = '[{linkname}]({{filename}}/{path}/{filename}.md)'.format(
|
||||||
linkname=linkname, path=path, filename=filename
|
linkname=linkname, path=path, filename=filename
|
||||||
|
@ -58,7 +58,7 @@ class ObsidianMarkdownReader(MarkdownReader):
|
||||||
|
|
||||||
def file_replacement(match):
|
def file_replacement(match):
|
||||||
filename, linkname = get_file_and_linkname(match)
|
filename, linkname = get_file_and_linkname(match)
|
||||||
path = FILES.get(filename)
|
path = FILE_PATHS.get(filename)
|
||||||
if path:
|
if path:
|
||||||
link_structure = '![{linkname}]({{static}}/{path}/{filename})'.format(
|
link_structure = '![{linkname}]({{static}}/{path}/{filename})'.format(
|
||||||
linkname=linkname, path=path, filename=filename
|
linkname=linkname, path=path, filename=filename
|
||||||
|
@ -93,24 +93,24 @@ class ObsidianMarkdownReader(MarkdownReader):
|
||||||
|
|
||||||
|
|
||||||
def populate_files_and_articles(article_generator):
|
def populate_files_and_articles(article_generator):
|
||||||
global ARTICLES
|
global ARTICLE_PATHS
|
||||||
global FILES
|
global FILE_PATHS
|
||||||
|
|
||||||
base_path = Path(article_generator.path)
|
base_path = Path(article_generator.path)
|
||||||
articles = base_path.glob('**/*.md')
|
articles = base_path.glob('**/*.md')
|
||||||
for article in articles:
|
for article in articles:
|
||||||
full_path, filename_w_ext = os.path.split(article)
|
full_path, filename_w_ext = os.path.split(article)
|
||||||
filename, ext = os.path.splitext(filename_w_ext)
|
filename, ext = os.path.splitext(filename_w_ext)
|
||||||
full_path = str(full_path).replace(str(base_path) + '/', '')
|
path = str(full_path).replace(str(base_path) + '/', '')
|
||||||
ARTICLES[filename] = full_path
|
ARTICLE_PATHS[filename] = path
|
||||||
|
|
||||||
globs = [base_path.glob('**/*.{}'.format(ext)) for ext in ['png', 'jpg', 'svg', 'apkg', 'gif']]
|
globs = [base_path.glob('**/*.{}'.format(ext)) for ext in ['png', 'jpg', 'svg', 'apkg', 'gif']]
|
||||||
files = chain(*globs)
|
files = chain(*globs)
|
||||||
|
|
||||||
for _file in files:
|
for _file in files:
|
||||||
full_path, filename_w_ext = os.path.split(_file)
|
full_path, filename_w_ext = os.path.split(_file)
|
||||||
full_path = str(full_path).replace(str(base_path) + '/', '')
|
path = str(full_path).replace(str(base_path) + '/', '')
|
||||||
FILES[filename_w_ext] = full_path
|
FILE_PATHS[filename_w_ext] = path
|
||||||
|
|
||||||
|
|
||||||
def modify_reader(article_generator):
|
def modify_reader(article_generator):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user