Skip to content

Commit 85ad6f6

Browse files
committed
feat: auto-fetch page title for link posts
Update the /link command to accept a URL instead of a title and auto-fetch the linked page's <title> as linkTitle. Add a computed title fallback in eleventyComputed.js that derives "Link: <linkTitle>" when no explicit title is set.
1 parent eaefdbc commit 85ad6f6

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

.claude/commands/link.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
argument-hint: [title]
2+
argument-hint: [url]
33
description: Create a new link blog post
44
---
55

66
Create a new link blog post with the following specifications:
77

8-
**Title**: $REMAINING_ARGS (all arguments)
8+
**URL**: $REMAINING_ARGS (all arguments)
99

10-
If no title is provided, prompt the user for a title interactively.
10+
If no URL is provided, prompt the user for the URL interactively.
1111

1212
**Steps to create the link post:**
1313

@@ -17,15 +17,15 @@ If no title is provided, prompt the user for a title interactively.
1717
TZ=America/Phoenix date +"%Y-%m-%d %H:%M:%S -07:00"
1818
```
1919

20-
2. If no title was provided, ask the user: "What is the title for this link post?"
20+
2. If no URL was provided, ask the user: "What is the URL for this link?"
2121

22-
3. Ask the user: "What is the URL for this link?"
22+
3. Fetch the linked page using `WebFetch` and extract the `<title>` tag content. This becomes the `linkTitle`. Clean up the title by trimming whitespace and removing any site name suffixes after common separators like ` | `, ` - `, ``, or ` · ` (only remove the last such segment if it looks like a site name, i.e., 3 words or fewer).
2323

2424
4. Ask the user: "Do you have a via URL?" (optional — the URL where you found the link, e.g., Hacker News, a blog, etc.)
2525

2626
5. Ask the user: "Do you have a blockquote to include?" (optional — a quote from the linked article to include in the post body)
2727

28-
6. Generate a slugified directory name from the title:
28+
6. Generate a slugified directory name from the `linkTitle`:
2929

3030
- Aim for around 5 words maximum - remove filler words like "a", "the", "to", "for", "using", "how"
3131
- Focus on the core concepts and key terms
@@ -51,7 +51,7 @@ If no title is provided, prompt the user for a title interactively.
5151
- article
5252
- link
5353
author: eric
54-
title: <user-provided title>
54+
linkTitle: <fetched page title>
5555
date: <datetime from step 1>
5656
linkUrl: <user-provided URL>
5757
viaUrl: <user-provided via URL>
@@ -63,6 +63,9 @@ If no title is provided, prompt the user for a title interactively.
6363

6464
Note: Only include the `viaUrl` field if the user provided a via URL.
6565

66+
Note: Do NOT include a `title` field — it will be computed automatically
67+
from `linkTitle` by the data cascade in `www/_data/eleventyComputed.js`.
68+
6669
11. After the frontmatter, add the post body:
6770

6871
- If the user provided a blockquote, include it as a markdown blockquote (prefixed with `> `)
@@ -82,5 +85,6 @@ If no title is provided, prompt the user for a title interactively.
8285
- Always use the `-07:00` timezone offset
8386
- Tags (`article` and `link`) MUST be included in the frontmatter
8487
- Do NOT include `layout` in the frontmatter — it is provided by the data cascade in `www/links/links.json`
88+
- Do NOT include `title` in the frontmatter — it is computed from `linkTitle` by `www/_data/eleventyComputed.js`
8589
- The `linkUrl` field is required and should be a full URL (e.g., `https://example.com/article`)
8690
- The `viaUrl` field is optional and should be a full URL if provided

www/_data/eleventyComputed.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ function extractTilTopic(filePathStem) {
2222
}
2323

2424
export default {
25+
// Compute title from linkTitle for link posts without an explicit title
26+
title: (data) => {
27+
if (data.title) return data.title
28+
if (data.linkTitle) return `Link: ${data.linkTitle}`
29+
return data.title
30+
},
31+
2532
// Extract topic from directory path for TILs
2633
tilTopic: (data) => extractTilTopic(data.page.filePathStem),
2734

0 commit comments

Comments
 (0)