refactor #1
@ -76,7 +76,7 @@ def build_site(site: SiteConfig, templates: DotMap):
|
||||
|
||||
def main():
|
||||
logger.info('Loading config.')
|
||||
with open('/home/jim/projects/shepich.com/config.yaml', 'r') as config_file:
|
||||
with open('./config.yaml', 'r') as config_file:
|
||||
config = yaml.safe_load(config_file.read())
|
||||
|
||||
logger.info('Loading global templates.')
|
||||
|
||||
@ -3,7 +3,7 @@ import glob
|
||||
import yaml
|
||||
import markdown
|
||||
import pydantic
|
||||
from typing import Optional
|
||||
from typing import Optional, Union
|
||||
from dotmap import DotMap
|
||||
from datetime import date
|
||||
|
||||
@ -26,7 +26,7 @@ class Article(pydantic.BaseModel):
|
||||
metadata: Optional[ArticleMetadata] = None
|
||||
|
||||
|
||||
def load_markdown(md: str) -> tuple[ArticleMetadata|None, str]:
|
||||
def load_markdown(md: str) -> tuple[Optional[ArticleMetadata], str]:
|
||||
'''Loads a Markdown file into a (metadata: ArticleMetadata, content: str) pair.'''
|
||||
|
||||
# Load the file contents if a filepath is specified, and strip document delimiters ('---').
|
||||
@ -59,7 +59,7 @@ def build_index(site: SiteConfig) -> dict[str, Article]:
|
||||
for a in site.articles or {}:
|
||||
expanded_article_list.extend(
|
||||
# Article paths are defined relative to the build cache; construct the full path.
|
||||
glob.glob(f'{site.build_cache}/{a.removeprefix('./').lstrip("/")}')
|
||||
glob.glob(f"{site.build_cache}/{a.removeprefix('./').lstrip('/')}")
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -103,21 +103,21 @@ def build_blog_archive(
|
||||
**kwargs
|
||||
)
|
||||
|
||||
with open(f'{site.web_root.rstrip('/')}/archive.html', 'w') as f:
|
||||
with open(f"{site.web_root.rstrip('/')}/archive.html", 'w') as f:
|
||||
f.write(archive_html_page)
|
||||
|
||||
|
||||
def build_rss_feed(site: SiteConfig, index: dict[str, Article]):
|
||||
feed = rfeed.Feed(
|
||||
title = site.title,
|
||||
link = f'{site.base_url.rstrip('/')}/rss.xml',
|
||||
link = f"{site.base_url.rstrip('/')}/rss.xml",
|
||||
description = site.description,
|
||||
language = "en-US",
|
||||
lastBuildDate = datetime.now(),
|
||||
items = [
|
||||
rfeed.Item(
|
||||
title = article.metadata.title,
|
||||
link = f'{site.base_url.rstrip('/')}/{article.path}',
|
||||
link = f"{site.base_url.rstrip('/')}/{article.path}",
|
||||
description = article.metadata.description,
|
||||
author = article.metadata.author,
|
||||
guid = rfeed.Guid(article.path),
|
||||
@ -131,5 +131,5 @@ def build_rss_feed(site: SiteConfig, index: dict[str, Article]):
|
||||
]
|
||||
)
|
||||
|
||||
with open(f'{site.web_root.rstrip('/')}/rss.xml', 'w') as f:
|
||||
with open(f"{site.web_root.rstrip('/')}/rss.xml", 'w') as f:
|
||||
f.write(feed.rss())
|
||||
Loading…
x
Reference in New Issue
Block a user