{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "207d2510", "metadata": {}, "outputs": [], "source": [ "import os\n", "import re\n", "import shutil\n", "import markdown\n", "import yaml\n", "import subprocess\n", "import rfeed\n", "import pydantic\n", "import glob\n", "from dotmap import DotMap\n", "from typing import Optional, Union, Literal, BinaryIO, Any\n", "\n", "\n", "\n", "from datetime import datetime\n", "from jimsite import *" ] }, { "cell_type": "code", "execution_count": null, "id": "8f435a12", "metadata": {}, "outputs": [], "source": [ "with open('config.yaml', 'r') as config_file:\n", " config = yaml.safe_load(config_file.read())\n", " \n", "templates = map_templates(config['templates_folder'])\n", "\n", "sites = {k:SiteConfig(**v) for k,v in config['sites'].items()}" ] }, { "cell_type": "code", "execution_count": null, "id": "e32458c7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Dogma Jimfiniumhttp://localhost:8000/dogma-jimfinium/rssDogma Jimfiniumen-USThu, 29 Jan 2026 16:29:57 GMTrfeed v1.1.1https://github.com/svpino/rfeed/blob/master/README.mdSuperlockhttp://localhost:8000/dogma-jimfinium/superlockJim Shepich IIIWed, 26 Nov 2025 00:00:00 GMTsuperlockSustainable Livinghttp://localhost:8000/dogma-jimfinium/sustainable-livingJim Shepich IIIThu, 20 Nov 2025 00:00:00 GMTsustainable-livingStocking Uphttp://localhost:8000/dogma-jimfinium/stocking-upJim Shepich IIIWed, 19 Nov 2025 00:00:00 GMTstocking-upSet Up the Toyshttp://localhost:8000/dogma-jimfinium/set-up-the-toysJim Shepich IIIWed, 14 Jan 2026 00:00:00 GMTset-up-the-toysDo What You Lovehttp://localhost:8000/dogma-jimfinium/do-what-you-loveJim Shepich IIITue, 10 Jun 2025 00:00:00 GMTdo-what-you-loveSelf-Care is not Selfishhttp://localhost:8000/dogma-jimfinium/self-care-is-not-selfishJim Shepich IIISun, 18 May 2025 00:00:00 GMTself-care-is-not-selfishBlowoutshttp://localhost:8000/dogma-jimfinium/blowoutsJim Shepich IIIWed, 26 Nov 2025 00:00:00 GMTblowoutsVitamins & Supplementshttp://localhost:8000/dogma-jimfinium/vitaminsJim Shepich IIISun, 18 May 2025 00:00:00 GMTvitaminsGear for New Parentshttp://localhost:8000/dogma-jimfinium/gear-for-new-parentsJim Shepich IIIFri, 12 Jul 2024 00:00:00 GMTgear-for-new-parents\n" ] } ], "source": [ "def build_rss_feed(site: SiteConfig, index: dict[str, tuple[ArticleMetadata, str]]):\n", " feed = rfeed.Feed(\n", " title = site.title,\n", " link = f'{site.base_url.rstrip('/')}/rss.xml',\n", " description = site.description,\n", " language = \"en-US\",\n", " lastBuildDate = datetime.now(),\n", " items = [\n", " rfeed.Item(\n", " title = metadata.title,\n", " link = f'{site.base_url.rstrip('/')}/{filestem}.md', \n", " description = metadata.description,\n", " author = metadata.author,\n", " guid = rfeed.Guid(filestem),\n", " pubDate = datetime(metadata.date.year, metadata.date.month, metadata.date.day)\n", " )\n", " for filestem, (metadata, _) in index.items()\n", " ]\n", " )\n", "\n", " # print(rss_feed.rss())" ] }, { "cell_type": "code", "execution_count": 15, "id": "70408b85", "metadata": {}, "outputs": [], "source": [ "def build_articles(site: SiteConfig, index: dict[str, tuple[ArticleMetadata, str]]):\n", " '''Generates HTML files for all of a given site's Markdown articles\n", " by interpolating the contents and metadata into the HTML templates.'''\n", "\n", " for filestem, (metadata, content) in index.items():\n", " article = format_html_template(\n", " 'templates/components/blog_article.html',\n", " content = content,\n", " blog_tags = ' '.join(format_blog_tags(metadata.tags)),\n", " metadata = metadata\n", " )\n", "\n", " page = format_html_template(\n", " 'templates/pages/default.html',\n", " content = article,\n", " partials = templates.partials\n", " )\n", "\n", " with open(f'{site.web_root.rstrip('/')}/{filestem}.html', 'w') as f:\n", " f.write(page)\n", "\n", " " ] }, { "cell_type": "code", "execution_count": null, "id": "7de0d84d", "metadata": {}, "outputs": [], "source": [ "\n", "index = {}\n", "\n", "for article in glob.glob('build/dogma-jimfinium/*.md'):\n", " metadata, content = load_markdown(article)\n", "\n", " if metadata is None:\n", " print(article)\n", "\n", " # Skip unpublished articles.\n", " if not metadata.published:\n", " continue\n", "\n", " article_filestem = os.path.splitext(os.path.basename(article))[0]\n", "\n", " # Add the article to the index.\n", " index[article_filestem] = (metadata, content)\n", "\n", " # Interpolate the article contents into the webpage template.\n", " article_html = format_html_template(\n", " 'templates/components/blog_article.html',\n", " content = content,\n", " blog_tags = ' '.join(format_blog_tags(metadata.tags)),\n", " metadata = metadata\n", " )\n", " html = format_html_template('templates/pages/default.html', content = article_html, **PARTIALS)\n", " \n", " # Write the HTML file to /dist/dogma-jimfinium.\n", " with open(f'dist/dogma-jimfinium/{article_filestem}.html', 'w') as f:\n", " f.write(html)\n", "\n", "\n", "index_html = build_blog_archive(index, **PARTIALS)\n", "# Write the HTML file to /dist/dogma-jimfinium.\n", "with open(f'dist/dogma-jimfinium/index.html', 'w') as f:\n", " f.write(index_html)" ] }, { "cell_type": "code", "execution_count": null, "id": "e3171afd", "metadata": {}, "outputs": [], "source": [ "def build_site(site: SiteConfig):\n", "\n", " # Initialize the build cache and web root, in case they do not exist.\n", " os.makedirs(site.build_cache, exist_ok = True)\n", " os.makedirs(site.web_root, exist_ok = True)\n", "\n", " # If the site is built from a git repo, pull that repo into the build cache.\n", " if site.git_repo:\n", " pull_git_repo(site.git_repo, site.build_cache)\n", "\n", " # Copy the sites assets into the web root.\n", " copy_assets(site)\n", "\n", " # Load the site's articles into an index.\n", " index = build_index(site)\n", "\n", " # Generate HTML pages for the articles.\n", " build_articles(site, index)\n", "\n", " " ] }, { "cell_type": "code", "execution_count": 16, "id": "a28b95a6", "metadata": {}, "outputs": [], "source": [ "build_site(sites['dogma_jimfinium'])" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }