jimsite/testbench.ipynb

223 lines
7.7 KiB
Plaintext

{
"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": "68b107f1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"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": [
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
"<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"><channel><title>Dogma Jimfinium</title><link>http://localhost:8000/dogma-jimfinium/rss</link><description>Dogma Jimfinium</description><language>en-US</language><lastBuildDate>Thu, 29 Jan 2026 16:29:57 GMT</lastBuildDate><generator>rfeed v1.1.1</generator><docs>https://github.com/svpino/rfeed/blob/master/README.md</docs><item><title>Superlock</title><link>http://localhost:8000/dogma-jimfinium/superlock</link><author>Jim Shepich III</author><pubDate>Wed, 26 Nov 2025 00:00:00 GMT</pubDate><guid isPermaLink=\"true\">superlock</guid></item><item><title>Sustainable Living</title><link>http://localhost:8000/dogma-jimfinium/sustainable-living</link><author>Jim Shepich III</author><pubDate>Thu, 20 Nov 2025 00:00:00 GMT</pubDate><guid isPermaLink=\"true\">sustainable-living</guid></item><item><title>Stocking Up</title><link>http://localhost:8000/dogma-jimfinium/stocking-up</link><author>Jim Shepich III</author><pubDate>Wed, 19 Nov 2025 00:00:00 GMT</pubDate><guid isPermaLink=\"true\">stocking-up</guid></item><item><title>Set Up the Toys</title><link>http://localhost:8000/dogma-jimfinium/set-up-the-toys</link><author>Jim Shepich III</author><pubDate>Wed, 14 Jan 2026 00:00:00 GMT</pubDate><guid isPermaLink=\"true\">set-up-the-toys</guid></item><item><title>Do What You Love</title><link>http://localhost:8000/dogma-jimfinium/do-what-you-love</link><author>Jim Shepich III</author><pubDate>Tue, 10 Jun 2025 00:00:00 GMT</pubDate><guid isPermaLink=\"true\">do-what-you-love</guid></item><item><title>Self-Care is not Selfish</title><link>http://localhost:8000/dogma-jimfinium/self-care-is-not-selfish</link><author>Jim Shepich III</author><pubDate>Sun, 18 May 2025 00:00:00 GMT</pubDate><guid isPermaLink=\"true\">self-care-is-not-selfish</guid></item><item><title>Blowouts</title><link>http://localhost:8000/dogma-jimfinium/blowouts</link><author>Jim Shepich III</author><pubDate>Wed, 26 Nov 2025 00:00:00 GMT</pubDate><guid isPermaLink=\"true\">blowouts</guid></item><item><title>Vitamins &amp; Supplements</title><link>http://localhost:8000/dogma-jimfinium/vitamins</link><author>Jim Shepich III</author><pubDate>Sun, 18 May 2025 00:00:00 GMT</pubDate><guid isPermaLink=\"true\">vitamins</guid></item><item><title>Gear for New Parents</title><link>http://localhost:8000/dogma-jimfinium/gear-for-new-parents</link><author>Jim Shepich III</author><pubDate>Fri, 12 Jul 2024 00:00:00 GMT</pubDate><guid isPermaLink=\"true\">gear-for-new-parents</guid></item></channel></rss>\n"
]
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "70408b85",
"metadata": {},
"outputs": [],
"source": []
},
{
"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_article_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": []
},
{
"cell_type": "code",
"execution_count": 4,
"id": "a28b95a6",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'build_site' is not defined",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mNameError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mbuild_site\u001b[49m(sites[\u001b[33m'\u001b[39m\u001b[33mresume\u001b[39m\u001b[33m'\u001b[39m])\n",
"\u001b[31mNameError\u001b[39m: name 'build_site' is not defined"
]
}
],
"source": [
"build_site(sites['resume'])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "60378277",
"metadata": {},
"outputs": [],
"source": [
"import inspect"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cd7fb9f3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"DotMap(a=DotMap(b=DotMap(c=42)))\n",
"a\n",
"DotMap(b=DotMap(c=42))\n",
"b\n",
"DotMap(c=42)\n",
"c\n"
]
},
{
"data": {
"text/plain": [
"42"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "fcd2faf5",
"metadata": {},
"outputs": [],
"source": []
}
],
"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
}