feat: use article body excerpt for OG description - #133
Merged
Conversation
Contributor
|
🔍 Preview deployed to: https://wktk.moe/pr-preview-133/ |
…kdown Regex-stripping raw Markdown/MDX source couldn't reliably handle the site's remark/rehype pipeline (math, admonitions, link cards, autolink headings, etc). Astro's content loader already stores the fully rendered HTML for each entry (`entry.rendered.html`), so strip that instead, which only requires handling real HTML tags/entities. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Myi55GMKN6FaoJdCGcVvnb
Replace the manual HTML-tag-stripping regex with hast-util-from-html (parse5-backed HTML parser), hast-util-to-text (innerText-like plain text extraction), and unist-util-remove (drop the decorative "#" heading-anchor links before extracting text) — all official packages from the same unified/syntax-tree collective that already powers this site's Markdown pipeline. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Myi55GMKN6FaoJdCGcVvnb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/lib/excerpt.ts, which strips common Markdown/MDX syntax (code fences, headings, links, emphasis, etc.) from an article's raw body and returns a short plain-text excerpt.description/og:descriptionmeta tags, instead of always falling back to the site-wide description.description→ excerpt from body → site description (unchanged behavior for body-less/redirect articles, which still show the site description).Test plan
npm run buildregenerates all OG images and article pages2024/dns-check) now shows an excerpt of its actual content in both the OG image and<meta name="description">/<meta property="og:description">npm run lintshows no new issues🤖 Generated with Claude Code
https://claude.ai/code/session_01Myi55GMKN6FaoJdCGcVvnb