projects

saturn

My website

feat: send /projects to showcase

daniel daum committed parent dc4c07e commit a8ed543Verified signature by Daniel Daum

Verifiedsigned by Daniel Daum with SSH key SHA256:drhIqfmUzuijEg5lpF1wfHhbG2Z4ebL9Lf+nLCJWAfg

Showing 8 changed files with 61 additions and 12 deletions.

_routes.json +1 −1
@@ -1,5 +1,5 @@11{22    "version": 1,3    "include": ["/about/*", "/now/*", "/blog/*", "/projects/*", "/api/*"],3    "include": ["/about/*", "/now/*", "/blog/*", "/projects", "/projects/*", "/api/*"],44    "exclude": []55}
about/index.html +4 −1
@@ -140,9 +140,12 @@140140                    <p>141141                        I built this site to practice writing, share my142142                        thoughts, and publish things I find interesting. It's143                        mostly handwritten HTML and CSS - there's more on that143                        mostly handwritten HTML and CSS.144                        <!-- hidden: old project page, /projects/ is showcase now145                        - there's more on that144146                        <a href="/projects/saturn/">here</a> if you're145147                        interested.148                        -->146149                    </p>147150                    <h2 class="caps">my interests</h2>148151                    <p>
feed.xml +3 −1
@@ -15,6 +15,7 @@15151616  <!-- NEWEST FIRST. content: post body in CDATA, absolute URLs, no classes. -->171718  <!-- hidden: old project page, /projects/ is showcase now1819  <entry>1920    <title>Saturn</title>2021    <link rel="alternate" type="text/html" href="https://danieldaum.net/projects/saturn/" />@@ -69,6 +70,7 @@6970      <p>- Daniel</p>7071    ]]></content>7172  </entry>73  -->72747375  <entry>7476    <title>Wake Me Up When September Ends</title>@@ -127,7 +129,7 @@127129      <img src="https://assets.danieldaum.net/img/photos/reno-race-day.webp" alt="daniel running a relay race in Reno, Nevada" /></figure>128130      <h2>hi, I'm Daniel</h2>129131      <p>I'm a software engineer and student living in Oakland, California. I worked professionally building backend services and data infrastructure before going back to school. College wasn't affordable for me the first time around, so I'm finishing my computer science degree now! I'm also learning video game development on the side</p>130      <p>I built this site to practice writing, share my thoughts, and publish things I find interesting. It's mostly handwritten HTML and CSS - there's more on that <a href="https://danieldaum.net/projects/saturn/">here</a> if you're interested.</p>132      <p>I built this site to practice writing, share my thoughts, and publish things I find interesting. It's mostly handwritten HTML and CSS.</p>131133      <h2>my interests</h2>132134      <p>If I'm not working, I'm probably enjoying one of the following activities!</p>133135      <h4>Video games</h4>
index.html +2 −0
@@ -168,6 +168,7 @@168168                        </div>169169                    </a>170170                    -->171                    <!-- hidden: old project page, /projects/ is showcase now171172                    <a class="card" href="/projects/saturn/">172173                        <p class="card-type">Jan '26 &middot; re-design</p>173174                        <p class="card-title">Saturn</p>@@ -175,6 +176,7 @@175176                            A cozy yet minimalist personal website176177                        </p>177178                    </a>179                    -->178180                    <a class="card card--more" href="/projects/">179181                        <p class="card-title">all projects &rarr;</p>180182                    </a>
social/README.md +3 −2
@@ -10,6 +10,7 @@ likes and comments. everything for them lives in this folder, and none of it is1010| `functions/_middleware.js` | runs before a page is served and fills its `data-social` section from d1 |1111| `functions/api/like.js` | the like button posts here |1212| `functions/api/moderate.js` | the approve/delete page linked from new-comment emails |13| `functions/projects/` | not social: `/projects/` is showcase at code.danieldaum.net, redirected or proxied |1314| `email.js` | email worker: turns mail sent to `reply@replies.danieldaum.net` into comments |1415| `schema.sql` | the d1 tables: `Likes`, `LikeVoters`, `Comments` |1516| `wrangler.toml` | pages config (d1 binding) |@@ -44,13 +45,13 @@ put this at the end of the post, inside `<article>` if it has one. the template4445</section>4546```464747this works on `/about/`, `/now/<slug>/`, `/blog/<slug>/` and `/projects/<slug>/`. take the section out and the page has none.48this works on `/about/`, `/now/<slug>/` and `/blog/<slug>/`. `/projects/` is showcase (`functions/projects/`), so it has none. take the section out and the page has none.48494950`/now/` is a copy of the newest edition, so it points at that edition: `data-social="/now/<slug>/"`. update it with each new now post. comments always go on the edition, never on `/now/`.50515152### a new kind of page (e.g. `/books/<slug>/`)5253531. add it to `isLikeable()` in `lib.js`: `(blog|now|projects)` → `(blog|now|projects|books)`541. add it to `isLikeable()` in `lib.js`: `(blog|now)` → `(blog|now|books)`54552. add `"/books/*"` to `/_routes.json`. every path in there runs a function and isn't cached, so keep it narrow55563. add the section to the pages56574. `mise run social-email`: the worker uses `isLikeable()` too, so it rejects comments for the new pages until it's redeployed
social/functions/projects/[[path]].jsadded +29 −0
@@ -0,0 +1,29 @@1// /projects/ is showcase, the code site at code.danieldaum.net. the old pages2// under /projects/ in this repo are never served3//4// MODE "redirect": a 302 to the same path on code.danieldaum.net5// MODE "proxy": showcase served here, under /projects/. set "base_path":6// "/projects" in showcase's config first, so its links stay under /projects/.7// clone, go get and docker pull stay on code.danieldaum.net89const ORIGIN = "https://code.danieldaum.net";10const MODE = "redirect";1112export async function onRequest({ request }) {13    const url = new URL(request.url);14    if (MODE === "redirect") {15        const rest = url.pathname.replace(/^\/projects/, "") || "/";16        return Response.redirect(ORIGIN + rest + url.search, 302);17    }1819    // read-only, like the site it stands in for20    if (request.method !== "GET" && request.method !== "HEAD") {21        return new Response("method not allowed", { status: 405, headers: { Allow: "GET, HEAD", "Content-Type": "text/plain; charset=utf-8" } });22    }2324    // the origin is fixed, so only showcase's pages come back. cookies stay25    // here: showcase reads the theme cookie in the browser, not the server26    const upstream = new Request(ORIGIN + url.pathname + url.search, request);27    upstream.headers.delete("Cookie");28    return fetch(upstream, { redirect: "manual" });29}
social/lib.js +2 −2
@@ -3,9 +3,9 @@33export const SITE = "https://danieldaum.net";44export const REPLY_TO = "reply@replies.danieldaum.net";556// /about/, /now/, /now/<slug>/, /blog/<slug>/, /projects/<slug>/6// /about/, /now/, /now/<slug>/, /blog/<slug>/ (/projects/ is showcase, see functions/projects/)77export function isLikeable(path) {8    return /^\/(about|now)\/$|^\/(blog|now|projects)\/[a-z0-9-]+\/$/.test(path);8    return /^\/(about|now)\/$|^\/(blog|now)\/[a-z0-9-]+\/$/.test(path);99}10101111// ===== hmac =====
theme.js +17 −5
@@ -1,6 +1,13 @@1// one palette per visit: it holds while the tab is open, and the next visit gets the2// next one. without js the css stays moss and the theme button stays hidden.1// one palette per visit: it holds until the browser closes, and the next visit gets2// the next one. without js the css stays moss and the theme button stays hidden.3// a `theme` cookie on danieldaum.net carries the palette to code.danieldaum.net4// and back, so both sites show the same one. elsewhere (localhost, pages.dev)5// the cookie is host-only.36const themes = ["moss", "ink", "wine", "plum", "teal"]; // "flexoki"7const host = location.hostname;8const shared = host === "danieldaum.net" || host.endsWith(".danieldaum.net")9    ? "; domain=danieldaum.net; secure"10    : "";411512function after(theme) {613    return themes[(themes.indexOf(theme) + 1) % themes.length];@@ -9,17 +16,22 @@ function after(theme) {916function use(theme) {1017    document.documentElement.dataset.theme = theme;1118    try {19        document.cookie = `theme=${theme}; path=/; samesite=lax${shared}`;1220        sessionStorage.setItem("theme", theme);1321        localStorage.setItem("theme", theme);1422    } catch {}1523}162425// the cookie first (it may come from code.danieldaum.net), then this tab's1726let current = "moss";1827try {28    const cookie = /(?:^|;\s*)theme=([a-z]+)/.exec(document.cookie)?.[1];1929    const visit = sessionStorage.getItem("theme");20    current = themes.includes(visit)21        ? visit22        : after(localStorage.getItem("theme"));30    current = themes.includes(cookie)31        ? cookie32        : themes.includes(visit)33          ? visit34          : after(localStorage.getItem("theme"));2335} catch {}2436use(current);2537