diff --git a/config.yaml b/config.yaml index 67db17b..c02a28d 100644 --- a/config.yaml +++ b/config.yaml @@ -9,7 +9,7 @@ sites: assets: - /assets articles: - - ./pages/*.md + - '*.md' template_selections: article: templates.components.simple_article @@ -50,6 +50,20 @@ sites: addons: - rss - # TODO: add Jimoire Laboratoire + jimoire_laboratoire: + title: Jimoire Laboratoire + description: How I built the Jimlab, and you can too! + base_url: http://localhost:8000/jimoire-laboratoire + git_repo: + url: ssh://gitea/jimlab/jimoire-laboratoire.git + branch: jimsite + lfs: false + build_cache: ./build/jimoire-laboratoire + web_root: ./dist/jimoire-laboratoire + assets: [] + articles: + - '*.md' + - 'essentials/*.md' + - '**/*.md' # TODO: add newsletter \ No newline at end of file diff --git a/jimsite/articles.py b/jimsite/articles.py index 8133211..e370f36 100644 --- a/jimsite/articles.py +++ b/jimsite/articles.py @@ -3,6 +3,7 @@ import glob import yaml import markdown import pydantic +import logging from typing import Optional, Union from dotmap import DotMap from datetime import date @@ -10,12 +11,14 @@ from datetime import date from .common import filepath_or_string, SiteConfig from .templating import format_html_template, TemplateSelections +logger = logging.getLogger(__name__) + class ArticleMetadata(pydantic.BaseModel): '''A model for the YAML frontmatter included with Markdown articles.''' title: str date: date - published: bool - tags: list + tags: Optional[list] = [] + published: Optional[bool] = False author: Optional[str] = None lastmod: Optional[date] = None thumbnail: Optional[str] = None @@ -41,6 +44,8 @@ def load_markdown(md: str) -> tuple[Optional[ArticleMetadata], str]: # Split the metadata from the contents. [raw_metadata, raw_article] = md.split('---') + + # TODO: Consider adding an optional postscript document, for things like unescaped CSS. # Use YAML to parse the metadata. metadata = yaml.safe_load(raw_metadata) @@ -66,21 +71,23 @@ def build_index(site: SiteConfig) -> dict[str, Article]: ) - for article_full_path in expanded_article_list: + for article_full_path in set(expanded_article_list): + + logger.debug(f'Loading article from {article_full_path}') metadata, content = load_markdown(article_full_path) + # TODO: consider adding support for articles with no metadata + if metadata is None: + logger.debug(f'Article loaded from {article_full_path} has no metadata. Skipping.') + continue + # Skip unpublished articles. if not metadata.published: + logger.debug(f'Article loaded from {article_full_path} is not published. Skipping.') continue - # Construct the article's path for the index by discarding the build cache - # and replacing .md with .html. - # article_path = article_full_path\ - # .removeprefix(site.build_cache)\ - # .lstrip('/')\ - # .replace('.md','.html') - # TODO: add tolerance for a hierarchical article directory structure. - article_path = os.path.basename(article_full_path).replace('.md', '.html') + # Construct the article's path for the index by discarding the build cache. + article_path = article_full_path.removeprefix(site.build_cache).lstrip("/").replace('.md','.html') index[article_path] = Article( path = article_path, @@ -147,7 +154,14 @@ def build_articles( ) - with open(f"{site.web_root.rstrip('/')}/{article.path}", 'w') as f: + # Construct the path to which the article page is to be saved. + destination = f"{site.web_root.rstrip('/')}/{article.path}" + + # Ensure the directory structure exists. + os.makedirs(os.path.dirname(destination), exist_ok=True) + + # Save the file. + with open(destination, 'w') as f: f.write(page_html) \ No newline at end of file diff --git a/jimsite/assets.py b/jimsite/assets.py index 13aec9c..7a3fc17 100644 --- a/jimsite/assets.py +++ b/jimsite/assets.py @@ -1,8 +1,10 @@ import os import glob import shutil +import logging from .common import run, GitRepo, SiteConfig +logger = logging.getLogger(__name__) def pull_git_repo(repo: GitRepo, build_cache: str) -> None: '''Pulls/clones a repo into the build cache directory.''' @@ -49,7 +51,7 @@ def copy_assets(site: SiteConfig) -> None: glob.glob(f'{site.build_cache}/{a.lstrip("/")}') ) - for asset in expanded_asset_list: + for asset in set(expanded_asset_list): # Skip ignored assets. if asset in ignored_asset_list: diff --git a/site/assets/css/theme.css b/site/assets/css/theme.css index 7661c4f..31c38e2 100644 --- a/site/assets/css/theme.css +++ b/site/assets/css/theme.css @@ -292,4 +292,8 @@ p.socials{ filter: brightness(0) saturate(100%) invert(95%) sepia(100%) saturate(14%) hue-rotate(213deg) brightness(104%) contrast(104%); margin-left: 0.25em; margin-right:0.25em; +} + +article ul, article ol{ + margin-bottom: 1em; } \ No newline at end of file diff --git a/site/pages/index.md b/site/index.md similarity index 100% rename from site/pages/index.md rename to site/index.md diff --git a/site/pages/404.html b/site/pages/404.html deleted file mode 100644 index 2a29fe2..0000000 --- a/site/pages/404.html +++ /dev/null @@ -1,9 +0,0 @@ -
-

404 Error

-
- - -
diff --git a/site/pages/about.html b/site/pages/about.html deleted file mode 100644 index c8b5d30..0000000 --- a/site/pages/about.html +++ /dev/null @@ -1,6 +0,0 @@ -
-

About

-
-Coming soon! - -
diff --git a/site/templates/components/blog_article.html b/site/templates/components/blog_article.html index 381a27c..5d9e7b7 100644 --- a/site/templates/components/blog_article.html +++ b/site/templates/components/blog_article.html @@ -12,9 +12,9 @@ {article.content}


- +   - +

Tags: {blog_tags}{templates.components.rss_icon}

\ No newline at end of file diff --git a/site/templates/partials/footer.html b/site/templates/partials/footer.html index 0f8c721..cb50ebb 100644 --- a/site/templates/partials/footer.html +++ b/site/templates/partials/footer.html @@ -1,5 +1,4 @@ \ No newline at end of file diff --git a/site/templates/partials/nav.html b/site/templates/partials/nav.html index e274537..cd98ba3 100644 --- a/site/templates/partials/nav.html +++ b/site/templates/partials/nav.html @@ -2,4 +2,5 @@ + \ No newline at end of file