From 450770f074f25d27d240a424d1a52214857fa73b Mon Sep 17 00:00:00 2001 From: "James R. Cogley" Date: Fri, 22 Nov 2024 21:29:42 +0900 Subject: [PATCH] update page --- src/index.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/src/index.md b/src/index.md index 287af42..501a83e 100644 --- a/src/index.md +++ b/src/index.md @@ -50,13 +50,76 @@ Of course if you search, there are plenty of ways to make a dynamic profile read * If you want to test locally, your environment needs Deno, and after cloning this repo, you can do `deno task lume --serve` to run it on `http://localhost:3000`. You can also go to this repo and use "use this template" to get your own copy, then clone that to local. * This repo creates a single web page based on the linktree-like [Theme Simple Me](https://github.com/lumeland/theme-simple-me) template for Lume, and hosts it on Github pages. But you can change `url: /` to `url: false` in `src/index.md` to disable the site. -* Edit the `repo-readme.vto` Vento template, using markdown format, to create the precursor readme. Notice the `url:` is set to a markdown file. +* Edit the `repo-readme.vto` Vento template, using markdown format, to create the precursor readme. Notice the `url:` in the file's frontmatter is set to output a markdown file. * On build via `deno task lume --serve` (builds and serves on localhost) or `deno task lume` (just builds), Lume will generate the site files in `_site`, and also run a script to copy the generated readme into place. -* +* See the script in Lume's config file `_config.ts` in the repo root, in the `site.script` line near the bottom. After the site is built, the readme generated by Vento is copied to the repo root as the typical `README.md` [here](https://github.com/RickCogley/rickcogley/blob/main/README.md). +* Take a look at the Vento template codes (`{{ something }}`) in the `repo-readme.vto` Vento template. You can see that it is pulling in the date, checking for a holiday name, and pulling in rss feeds. + +## Setting up the Data + +First take a look at the "Today is" line in the `repo-readme.vto` Vento template. + +``` +**Today is:** {{ todaysDateENUS }}{{ set today = todaysDateYYYYMMDD }}{{ if holidays[today] }} ({{ holidays[today] }}){{ /if }} +``` + +It's referencing the constants `todaysDateENUS` and `todaysDateYYYYMMDD`, and checking a dataset "holidays" if there is any data that matches "today". The constants and data are set up in the file `_data.ts`. For example: + +``` +export const todaysDateYYYYMMDD = `${new Date().toISOString().split("T")[0]}`; +``` + +This sets up a date in YYYY-MM-DD format, because that's what the holiday dataset has to match on. + +As for the holidays, they are fetched into an object `holidays` which the Vento template is parsing. + +``` +const response = await fetch('https://holidays-jp.github.io/api/v1/date.json', { + method: 'GET', + ... +``` + +If you needed to access a protected API, you could put its access token in a repository variable, and access it as a bearer token in the header of your get. + +Regarding RSS, I used "parse feed" from a library on denoland/x. This part: + +``` +import { parseFeed } from "https://deno.land/x/rss/mod.ts"; +async function fetchAndConvertRSS(url: string, limit: number) { + // Fetch the RSS feed + const response = await fetch(url); + ... +``` + +Then the feed can be fetched into a const to use in the Vento template. The Vento template just uses a for loop to parse the feed's json and put it into markdown `li` elements. + +``` +## Latest Statuses: +{{ for item of statuses.entries }}* [{{ item.description.value }}]({{ item.id }}) +{{ /for }} +``` + +## Automate Generation + +To automate the generation, we just use a github actions template, `.github/workflows/update-profile-readme.yml` which triggers Lume to build the site which copies the `README.md` into place, commits the new file, publishes to GH Pages. The actions template is triggered on push or PR, "workflow dispatch" which means you can also manually trigger, and on a cron schedule. + +``` +on: + push: + # Run on main branch pushes or PRs + branches: [main] + pull_request: + branches: [ "main" ] + # Allow to manually trigger the workflow + workflow_dispatch: + schedule: + # Rebuild every day at 9:06 PM UTC + - cron: "6 21 * * *" +``` ## How to use? -Go to the repo, "use this template" +Go to the repo, "use this template" then tweak it how you like. ## Is it good?