fix(seo): normalize meta descriptions to 160 chars and fix homepage head tag - #98
Merged
Merged
Conversation
…ead tag - Add cleanMetaDescription in backend and frontend to normalize whitespace, collapse newlines, and truncate cleanly at 160-char word boundaries - Add explicit meta description and sync OpenGraph tags on homepage (+page.svelte) - Ensure single article detail and server injection output concise, single-line descriptions - Add unit test suite TestCleanMetaDescription in api handlers
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.
Bug Description & Symptom
Bing Webmaster Tools reported "Too many pages with identical meta descriptions" across single article URLs and homepage. Crawlers were previously served duplicate global meta descriptions on non-existent slugs due to SPA fallback. Additionally, live article summaries contained raw newline breaks (
\n\n) and exceeded 300-400 characters, while the homepage lacked an explicit<meta name="description">tag in<svelte:head>.Root Cause Analysis
frontend/src/routes/+layout.sveltewhich was served on missing articles prior to 404 route handling.article.Summarywas injected directly into HTML attributes without collapsing newlines or truncating to search engine character recommendations (150-160 chars).+page.svelte) definedog:descriptionandtwitter:descriptionbut omitted<meta name="description">.Proposed Fix
cleanMetaDescription(text string, maxLen int) stringinbackend/internal/api/server.go:\r\n), tabs, and multiple spaces into a single space.....cleanMetaDescriptionininjectSEOTagsandserveIndexHTMLfor article detail endpoints.frontend/src/lib/seo.tswith identical logic and applied it to<meta name="description">,og:description,twitter:description, andNewsArticleJSON-LD infrontend/src/routes/[slug]/+page.svelte.<meta name="description">infrontend/src/routes/+page.svelteand synchronized with canonical site metadata.TestCleanMetaDescriptioninbackend/internal/api/handlers_test.go.Scope Lock & Blast Radius
TestCleanMetaDescriptionunit test covering edge cases, newlines, and truncation.Mandatory Zero-Failure Pre-Commit Verification (AGENTS.md)
All commands below must be executed locally and pass with Exit Code 0 prior to creating the PR:
Backend Suite (if backend code changed)
gofmt -w . && gofmt -l .(Output must be completely empty)go vet ./...(Static analysis clean)go test -count=1 -v ./...(All tests pass with cache disabled)Frontend Suite (if frontend code changed)
npm run format && npm run lint(Prettier code style & ESLint clean)npm run check(SvelteKit TypeScript validation clean)npm run build(Production build succeeds with static adapter)Live Localhost End-to-End (E2E) Verification (Mandatory)
go run ./cmd/server/ preview) with 0 startup crashes/panics.Local Verification Evidence