Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/syndicate-to-mastodon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Syndicate to Mastodon via Bridgy

on:
push:
branches:
- main
paths:
- "src/content/posts/**"

jobs:
syndicate:
name: Send webmentions to Bridgy Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Find added or modified posts
id: changed-posts
run: |
git diff --name-only --diff-filter=AM HEAD~1 HEAD -- src/content/posts/ \
| grep -E '\.(md|mdx)$' > changed_posts.txt || true
echo "Changed posts:"
cat changed_posts.txt

- name: Wait for Netlify deploy
run: |
echo "Waiting for site to reflect the latest deploy..."
for i in $(seq 1 30); do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://danmatthew.co.uk/)
if [ "$STATUS" = "200" ]; then
echo "Site is live (attempt $i)"
# Extra buffer to ensure new content is deployed
sleep 30
break
fi
echo "Not ready yet (attempt $i, status $STATUS), retrying in 10s..."
sleep 10
done

- name: Send webmentions to Bridgy
run: |
if [ ! -s changed_posts.txt ]; then
echo "No changed posts to syndicate."
exit 0
fi
while IFS= read -r post_file; do
if [ -z "$post_file" ]; then continue; fi
# Strip directory prefix and extension to get the slug
filename=$(basename "$post_file")
slug="${filename%.mdx}"
slug="${slug%.md}"
post_url="https://danmatthew.co.uk/notes/${slug}/"
echo "Sending webmention for: $post_url"
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
-X POST https://brid.gy/publish/webmention \
--data-urlencode "source=${post_url}" \
--data-urlencode "target=https://brid.gy/publish/mastodon")
echo "Bridgy responded with HTTP $HTTP_STATUS for $post_url"
done < changed_posts.txt
1 change: 1 addition & 0 deletions src/content.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const collections = {
.transform((str) => (str ? new Date(str) : undefined)),
published: z.boolean().default(true).optional(),
evergreen: z.boolean().optional(),
syndicationUrl: z.string().url().optional(),
}),
}),
articles: defineCollection({
Expand Down
2 changes: 2 additions & 0 deletions src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const { title, description, modifier } = Astro.props;
<meta name="theme-color" content="hsl(0, 0%, 99%)" />
<link rel="alternate" type="application/rss+xml" title="Dan Matthew" href="/feed.xml" />
<link rel="alternate" type="application/feed+json" title="Dan Matthew" href="/feed.json" />
<link rel="webmention" href="https://webmention.io/danmatthew.co.uk/webmention" />
<link rel="pingback" href="https://webmention.io/xmlrpc" />
</head>
<body>
<Nav />
Expand Down
15 changes: 12 additions & 3 deletions src/pages/notes/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,29 @@ export async function getStaticPaths() {
const { entry, prevPost, nextPost } = Astro.props;

const { Content } = await render(entry);

const canonicalUrl = new URL(`/notes/${entry.id}/`, Astro.site).toString();
const { syndicationUrl } = entry.data;
---

<BaseLayout title={`${entry.data.title}`}>
<article>
<article class="h-entry">
<Hero title={entry.data.title}>
<div slot="header-extras">
<div class="meta">
<time datetime={entry.data.publishedDate.toISOString()}>
<time class="dt-published" datetime={entry.data.publishedDate.toISOString()}>
{entry.data.publishedDate.toLocaleDateString("en-GB")}
</time>
</div>
</div>
</Hero>
<section class="flow">
<data class="p-name" value={entry.data.title} hidden></data>
<a class="u-url" href={canonicalUrl} hidden></a>
{syndicationUrl
? <a class="u-syndication" href={syndicationUrl} rel="syndication">View on Mastodon</a>
: <a class="u-syndication" href="https://brid.gy/publish/mastodon" rel="syndication" hidden></a>
}
<section class="e-content flow">
<Content />
</section>
</article>
Expand Down
Loading