Repository navigation
Route in-app writing links to the migrated archive #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import type { NavigationGuard } from 'vue-router'; | ||
|
|
||
| const WRITING_ARCHIVE_URL = 'https://writing.gocanto.sh/'; | ||
|
|
||
| export const createArchiveNavigationGuard = (navigate: (url: string) => void = (url) => window.location.assign(url)): NavigationGuard => { | ||
| return (to, from) => { | ||
| if (to.name === 'Writing' || to.name === 'TagPosts') { | ||
| navigate(WRITING_ARCHIVE_URL); | ||
| return false; | ||
| } | ||
|
|
||
| if (to.name === 'PostDetail' && from.matched.length > 0) { | ||
| // A document request lets Caddy apply each legacy post's canonical redirect. | ||
| navigate(to.fullPath); | ||
| return false; | ||
| } | ||
| }; | ||
| }; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { readFileSync } from 'node:fs'; | ||
| import { resolve } from 'node:path'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import canonicalRedirects from '../fixtures/writing-archive-redirects.json'; | ||
|
|
||
| const caddyfile = readFileSync(resolve(process.cwd(), 'caddy/WebCaddyfile.internal'), 'utf8'); | ||
| const redirects = [...caddyfile.matchAll(/^\s*redir (\/post\/\S+) (\S+) (\d+)$/gm)]; | ||
|
|
||
| // These targets match the existing API Caddy archive migration, including its slug corrections. | ||
| describe('production legacy writing redirects', () => { | ||
| it.each(Object.entries(canonicalRedirects))('redirects %s to its canonical archive target for humans', (path, target) => { | ||
| const rule = redirects.find((match) => match[1] === path); | ||
| expect(rule?.[2]).toBe(target); | ||
| expect(rule?.[3]).toBe('301'); | ||
| expect(rule?.index).toBeLessThan(caddyfile.indexOf('@force_seo')); | ||
| expect(rule?.index).toBeLessThan(caddyfile.indexOf('@share_post_bots')); | ||
| }); | ||
|
|
||
| it('only redirects mapped posts and keeps the SPA fallback for other routes', () => { | ||
| expect(redirects.map((match) => match[1]).toSorted()).toEqual(Object.keys(canonicalRedirects).toSorted()); | ||
| expect(caddyfile).not.toMatch(/redir \/post\/\*/); | ||
| expect(caddyfile).toMatch(/handle\s*{\s*root \* \/usr\/share\/caddy\s*try_files \{path\} \{path\}\/index\.html \/index\.html/s); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "/post/2026-02-19-local-first-skills-platform-for-ai-agents": "https://writing.gocanto.sh/local-first-skills-platform-for-ai-agents", | ||
| "/post/2023-06-21-bugs-are-inevitable-in-software-development": "https://writing.gocanto.sh/bugs-are-inevitable-in-software-development", | ||
| "/post/2025-09-25-shipping-seo-for-a-single-page-app-the-pragmatic-way": "https://writing.gocanto.sh/shipping-seo-for-a-single-page-app-the-pragmatic-way", | ||
| "/post/2025-10-09-when-a-real-time-feature-store-is-the-wrong-fix-for-fraud": "https://writing.gocanto.sh/when-a-real-time-feature-store-is-the-wrong-fix-for-fraud", | ||
| "/post/2025-11-04-your-ai-model-is-not-your-product": "https://writing.gocanto.sh/your-ai-model-is-not-your-product", | ||
| "/post/2026-04-05-go-meets-the-monolith-renaissance": "https://writing.gocanto.sh/go-meets-the-monolith-renaissance", | ||
| "/post/2025-12-29-nostalgia-is-a-security-risk": "https://writing.gocanto.sh/nostalgia-is-a-security-risk", | ||
| "/post/2025-11-21-demystifying-the-go-maps-engine": "https://writing.gocanto.sh/demystifying-the-go-maps-engine", | ||
| "/post/2025-12-15-money-in-Go-done-properly": "https://writing.gocanto.sh/money-in-go-done-properly", | ||
| "/post/2026-03-13-taming-complex-state-in-go": "https://writing.gocanto.sh/taming-complex-state-in-go", | ||
| "/post/2026-03-31-laravel-collections-to-go": "https://writing.gocanto.sh/laravel-collections-to-go", | ||
| "/post/2025-10-29-turbocharging-web-performance-automated-early-hints": "https://writing.gocanto.sh/turbocharging-web-performance-automated-early-hints", | ||
| "/post/2025-11-13-shipping-observability-for-oullin-infrastructure": "https://writing.gocanto.sh/shipping-observability-for-oullin-infrastructure", | ||
| "/post/2025-11-26-the-case-of-the-mismatched-clocks-lesson-secure-timing": "https://writing.gocanto.sh/the-case-of-the-mismatched-clocks-lesson-secure-timing", | ||
| "/post/2026-02-26-stop-installing-python-just-to-convert-files-to-markdown": "https://writing.gocanto.sh/stop-installing-python-just-to-convert-files-to-markdown", | ||
| "/post/2025-11-15-debugging-multi-layered-docker-deployment": "https://writing.gocanto.sh/debugging-multi-layered-docker-deployment", | ||
| "/post/2023-06-22-positive-emotions-reduce-negative-emotions": "https://writing.gocanto.sh/positive-emotions-reduce-negative-emotions", | ||
| "/post/2025-04-02-embrace-growth-through-movement": "https://writing.gocanto.sh/embrace-growth-through-movement", | ||
| "/post/2025-10-17-the-operating-system-of-you-an-engineering-leader-reflection": "https://writing.gocanto.sh/the-operating-system-of-you-an-engineering-leader-reflection", | ||
| "/post/2025-11-03-honesty-establishes-trust-enabling-process-formation-progression": "https://writing.gocanto.sh/honesty-establishes-trust-enabling-process-formation-progression", | ||
| "/post/2025-11-30-work-is-not-family-and-that-is-a-good-thing": "https://writing.gocanto.sh/work-is-not-family-and-that-is-a-good-thing", | ||
| "/post/2026-02-24-engineering-management-mistakes-we-need-to-stop-making.md": "https://writing.gocanto.sh/engineering-management-mistakes-we-need-to-stop-making", | ||
| "/post/2025-12-05-handling-money-in-php": "https://writing.gocanto.sh/handling-money-in-php", | ||
| "/post/2025-10-15-building-oullin": "https://writing.gocanto.sh/building-oullin" | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { createMemoryHistory, createRouter } from 'vue-router'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { createArchiveNavigationGuard } from '@support/archive-navigation'; | ||
|
|
||
| const setup = async (initialPath = '/') => { | ||
| const navigate = vi.fn(); | ||
| const component = { template: '<div />' }; | ||
| const router = createRouter({ | ||
| history: createMemoryHistory(), | ||
| routes: [ | ||
| { path: '/', name: 'Home', component }, | ||
| { path: '/writing', name: 'Writing', component }, | ||
| { path: '/tags/:tag', name: 'TagPosts', component }, | ||
| { path: '/post/:slug', name: 'PostDetail', component }, | ||
| { path: '/about', name: 'About', component }, | ||
| { path: '/contact', name: 'Contact', component }, | ||
| { path: '/projects', name: 'Projects', component }, | ||
| ], | ||
| }); | ||
| router.beforeEach(createArchiveNavigationGuard(navigate)); | ||
| await router.push(initialPath); | ||
| return { router, navigate }; | ||
| }; | ||
|
|
||
| describe('writing archive navigation', () => { | ||
| it.each(['/writing', '/writing/', '/writing?category=go', '/tags/go'])('sends %s to the migrated archive', async (path) => { | ||
| const { router, navigate } = await setup(); | ||
| await router.push(path); | ||
| expect(navigate).toHaveBeenCalledWith('https://writing.gocanto.sh/'); | ||
| expect(router.currentRoute.value.name).toBe('Home'); | ||
| }); | ||
|
|
||
| it('uses a document request for the canonical legacy post redirect, preserving query and hash', async () => { | ||
| const { router, navigate } = await setup(); | ||
| const path = '/post/2025-10-15-building-oullin?source=nav#architecture'; | ||
| await router.push({ name: 'PostDetail', params: { slug: '2025-10-15-building-oullin' }, query: { source: 'nav' }, hash: '#architecture' }); | ||
| expect(navigate).toHaveBeenCalledWith(path); | ||
| expect(router.currentRoute.value.name).toBe('Home'); | ||
| }); | ||
|
|
||
| it('does not loop on a direct request for an unmapped post', async () => { | ||
| const { router, navigate } = await setup('/post/unmapped-post'); | ||
| expect(navigate).not.toHaveBeenCalled(); | ||
| expect(router.currentRoute.value.name).toBe('PostDetail'); | ||
| }); | ||
|
|
||
| it.each(['/about', '/contact', '/projects'])('keeps %s in the SPA', async (path) => { | ||
| const { router, navigate } = await setup(); | ||
| await router.push(path); | ||
| expect(navigate).not.toHaveBeenCalled(); | ||
| expect(router.currentRoute.value.path).toBe(path); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.