timeline test

This commit is contained in:
m
2026-03-14 11:28:39 +01:00
parent 97675e7ba6
commit e48e80ed70
3 changed files with 75 additions and 68 deletions

View File

@@ -2,118 +2,107 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"id": "090c7992", "id": "090c7992",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" im still struggling:\n",
" </p>\n",
" <p>sudo pacman -S archlinux-keyring</p>\n",
" <p>melange:</p>\n",
" <ul>\n",
" <li><a href=\"/page2/line/lineplot.html\">machine learning with failed hyperparams</a></li>\n",
" <li><a href=\"/page2/dblp/bar/index.html\">the dblp dataset in bar plot</a></li>\n",
" <li><a href=\"/page2/dblp/edge/index.html\">the dblp dataset with an example of community</a></li>\n",
" <li><a href=\"/page2/dblp/full/index.html\">the dblp dataset of 5 years as a graph</a></li>\n",
" <li><a href=\"/page2/dblp/time/index.html\">the generated links as a graph</a></li>\n",
"\n",
" </ul>\n",
"\n",
"Post 3 updated successfully.\n"
]
}
],
"source": [ "source": [
"import datetime\n", "# git entry and print\n",
"\n",
"def get_entry(file_path, id):\n", "def get_entry(file_path, id):\n",
"\n",
" # 1. Import the current list to get the latest ID\n", " # 1. Import the current list to get the latest ID\n",
"\n", " # use a namespace to avoid path issues\n",
" # We use a namespace to avoid path issues\n",
"\n",
" namespace = {}\n", " namespace = {}\n",
"\n", "\n",
" with open(file_path, 'r') as f:\n", " with open(file_path, \"r\") as f:\n",
"\n",
" exec(f.read(), namespace)\n", " exec(f.read(), namespace)\n",
"\n", "\n",
" posts = namespace.get('BLOG_POSTS', [])\n", " posts = namespace.get(\"BLOG_POSTS\", [])\n",
"\n", "\n",
" for items in posts:\n", " for items in posts:\n",
"\n",
" if items.get(\"id\") == id:\n", " if items.get(\"id\") == id:\n",
"\n", " content = items.get(\"content\")\n",
" content = items.get('content')\n",
"\n",
" print(content)\n", " print(content)\n",
"\n", " return items\n",
" return items \n",
"\n",
"\n", "\n",
"\n", "\n",
"def update_entry(file_path, post_id, new_content):\n", "def update_entry(file_path, post_id, new_content):\n",
" # 1. Load the existing data into memory\n", " # 1. Load the existing data into memory\n",
" namespace = {}\n", " namespace = {}\n",
" with open(file_path, 'r') as f:\n", " with open(file_path, \"r\") as f:\n",
" exec(f.read(), namespace)\n", " exec(f.read(), namespace)\n",
" \n", "\n",
" posts = namespace.get('BLOG_POSTS', [])\n", " posts = namespace.get(\"BLOG_POSTS\", [])\n",
" \n", "\n",
" # 2. Find and update the specific post\n", " # 2. Find and update the specific post\n",
" found = False\n", " found = False\n",
" for post in posts:\n", " for post in posts:\n",
" if post.get(\"id\") == post_id:\n", " if post.get(\"id\") == post_id:\n",
" post['content'] = new_content\n", " post[\"content\"] = new_content\n",
" # Optional: Update the date or add an \"updated\" field\n", " # Optional: Update the date or add an \"updated\" field\n",
" # post['subtitle'] += \" (Updated)\" \n", " # post['subtitle'] += \" (Updated)\"\n",
" found = True\n", " found = True\n",
" break\n", " break\n",
" \n", "\n",
" if not found:\n", " if not found:\n",
" print(f\"Error: Post {post_id} not found.\")\n", " print(f\"Error: Post {post_id} not found.\")\n",
" return\n", " return\n",
"\n", "\n",
" # 3. Write the entire list back to the file\n", " # 3. Write the entire list back to the file\n",
" # Using repr() or a loop to format it cleanly\n", " # Using repr() or a loop to format it cleanly\n",
" with open(file_path, 'w') as f:\n", " with open(file_path, \"w\") as f:\n",
" f.write(\"BLOG_POSTS = [\\n\")\n", " f.write(\"BLOG_POSTS = [\\n\")\n",
" for p in posts:\n", " for p in posts:\n",
" # Use .get() to provide a default value if the key is missing\n", " # Use .get() to provide a default value if the key is missing\n",
" display_val = p.get('displayall', False) \n", " display_val = p.get(\"displayall\", False)\n",
" data_val = p.get('date', \"?\") \n", " data_val = p.get(\"date\", \"?\")\n",
" subtitle_val = p.get('subtitle', \"\") \n", " subtitle_val = p.get(\"subtitle\", \"\")\n",
" \n", "\n",
" entry = f\"\"\" {{\n", " entry = f\"\"\" {{\n",
" 'id': {p['id']},\n", " 'id': {p[\"id\"]},\n",
" 'title': \"{p['title']}\",\n", " 'title': \"{p[\"title\"]}\",\n",
" 'subtitle': \"{subtitle_val}\",\n", " 'subtitle': \"{subtitle_val}\",\n",
" 'date': \"{data_val}\",\n", " 'date': \"{data_val}\",\n",
" 'content': \\\"\\\"\\\"{p['content']}\\\"\\\"\\\",\n", " 'content': \\\"\\\"\\\"{p[\"content\"]}\\\"\\\"\\\",\n",
" \"displayall\": {display_val}\n", " \"displayall\": {display_val}\n",
" }},\\n\"\"\"\n", " }},\\n\"\"\"\n",
" f.write(entry)\n", " f.write(entry)\n",
" f.write(\"]\\n\")\n", " f.write(\"]\\n\")\n",
" \n", "\n",
" print(f\"Post {post_id} updated successfully.\")\n", " print(f\"Post {post_id} updated successfully.\")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "7c80d17a",
"metadata": {},
"outputs": [],
"source": [
"FIEL_PATH = \"../content/posts.py\"\n",
"get_entry(FIEL_PATH, 0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e2048547",
"metadata": {},
"outputs": [],
"source": [
"\n", "\n",
"# --- Usage Example ---\n", "# --- Usage Example ---\n",
"if __name__ == \"__main__\":\n", "if __name__ == \"__main__\":\n",
" file = '../content/posts.py'\n", " file = \"../content/posts.py\"\n",
" target_id = 3\n", " target_id = 3\n",
" \n", "\n",
" # Get the old one first to see it\n", " # Get the old one first to see it\n",
" old_post = get_entry(file, target_id)\n", " old_post = get_entry(file, target_id)\n",
" \n", "\n",
" if old_post:\n", " if old_post:\n",
" pass\n", " pass\n",
"\n", "\n",
" new_text=\"\"\"\n", " new_text = \"\"\"\n",
" <p>sudo pacman -S archlinux-keyring</p>\n", " <p>sudo pacman -S archlinux-keyring</p>\n",
" <p>sudo pacman -Sc</p>\n", " <p>sudo pacman -Sc</p>\n",
" <p>melange:</p>\n", " <p>melange:</p>\n",
@@ -128,15 +117,14 @@
"\n", "\n",
"\n", "\n",
" \"\"\"\n", " \"\"\"\n",
" \n", "\n",
" \n", " update_entry(file, target_id, new_text)"
" update_entry(file, target_id, new_text)\n"
] ]
} }
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "base", "display_name": "graphx",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@@ -150,7 +138,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.11.7" "version": "3.11.11"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@@ -0,0 +1,16 @@
<div class="max-w-3xl mx-auto px-6 py-16">
<ol class="relative border-l border-gray-300">
{% for item in timeline %}
<li class="mb-10 ml-6">
<span
class="absolute flex items-center justify-center w-6 h-6 bg-gray-200 rounded-full -left-3"
>
</span>
<h3 class="font-semibold text-lg">{{ item.title }}</h3>
<p class="text-gray-600">{{ item.description }}</p>
</li>
{% endfor %}
</ol>
</div>

View File

@@ -0,0 +1,3 @@
<h1 class="text-3xl font-bold mb-8">Project Timeline</h1>
{% include "components/timeline.html" %}