Skip to content

Commit cf5ee95

Browse files
teimurjanclaude
andcommitted
feat: add privacy and terms routes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d47cd8b commit cf5ee95

5 files changed

Lines changed: 95 additions & 17 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { legalPageResponse, listLegalPagePaths, readLegalPage } from '@/lib/legal'
2+
3+
export const dynamic = 'force-static'
4+
5+
interface LegalPageRouteProps {
6+
params: Promise<{ path?: string[] }>
7+
}
8+
9+
export async function generateStaticParams() {
10+
const paths = await listLegalPagePaths('privacy')
11+
return paths.map((path) => ({ path }))
12+
}
13+
14+
export async function GET(_request: Request, { params }: LegalPageRouteProps) {
15+
const { path } = await params
16+
return legalPageResponse(await readLegalPage('privacy', path))
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { legalPageResponse, listLegalPagePaths, readLegalPage } from '@/lib/legal'
2+
3+
export const dynamic = 'force-static'
4+
5+
interface LegalPageRouteProps {
6+
params: Promise<{ path?: string[] }>
7+
}
8+
9+
export async function generateStaticParams() {
10+
const paths = await listLegalPagePaths('terms')
11+
return paths.map((path) => ({ path }))
12+
}
13+
14+
export async function GET(_request: Request, { params }: LegalPageRouteProps) {
15+
const { path } = await params
16+
return legalPageResponse(await readLegalPage('terms', path))
17+
}

‎workspaces/website/content/legal/skill-keyword-metrics/privacy.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Querygauge Privacy Policy
22

3-
Effective November 5, 2026. This policy covers [Querygauge](/lab/querygauge), a private tool that only I, Teimur Gasanov, use.
3+
Effective November 5, 2026. This policy covers Querygauge, a private tool that only I, Teimur Gasanov, use.
44

55
## Data access
66

‎workspaces/website/content/legal/skill-keyword-metrics/terms.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Querygauge Terms of Service
22

3-
Effective November 5, 2026. These terms cover [Querygauge](/lab/querygauge), a private tool that only I, Teimur Gasanov, use.
3+
Effective November 5, 2026. These terms cover Querygauge, a private tool that only I, Teimur Gasanov, use.
44

55
The tool is not available to the public. It has no accounts or payments.
66

7-
The use of the tool must follow the [Google Ads API Terms and Conditions](https://developers.google.com/google-ads/api/terms). The [Privacy Policy](/lab/querygauge/privacy) tells how the tool handles Google user data.
7+
The use of the tool must follow the [Google Ads API Terms and Conditions](https://developers.google.com/google-ads/api/terms). The [Privacy Policy](/privacy/skill-keyword-metrics) tells how the tool handles Google user data.
88

99
The tool is provided as is, with no warranty. The metrics are estimates from Google.
1010

‎workspaces/website/lib/legal.ts‎

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,80 @@
11
import { readFile, readdir } from 'node:fs/promises'
22
import { join } from 'node:path'
33
import { marked } from 'marked'
4+
import { notFound } from 'next/navigation'
45

5-
const LAB_DIR = join(process.cwd(), 'content/lab')
6+
export type LegalDoc = 'privacy' | 'terms'
67

7-
// GitHub Pages serves /lab/x/privacy from privacy.html, but the dev server only accepts clean URLs.
8-
const toUrlPath = (file: string): string[] =>
9-
process.env.NODE_ENV === 'development'
10-
? file.replace(/(\/index)?\.md$/, '').split('/')
11-
: file.replace(/\.md$/, '.html').split('/')
8+
const LEGAL_DIR = join(process.cwd(), 'content/legal')
129

13-
export const listLabPagePaths = async (): Promise<string[][]> => {
14-
const files = await readdir(LAB_DIR, { recursive: true })
15-
return files.filter((file) => file.endsWith('.md')).map(toUrlPath)
10+
const INDEX_TITLES: Record<LegalDoc, string> = {
11+
privacy: 'Privacy Policies',
12+
terms: 'Terms of Service',
1613
}
1714

18-
export const readLabPage = ([project, page = 'index']: string[]): Promise<string | null> =>
19-
readFile(join(LAB_DIR, project, `${page.replace(/\.html$/, '')}.md`), 'utf8').catch(() => null)
15+
// GitHub Pages serves /x from x.html and /x/ from x/index.html, but the dev server only accepts clean URLs.
16+
const toStaticPath = (project?: string): string[] => {
17+
if (process.env.NODE_ENV === 'development') return project ? [project] : []
18+
return [`${project ?? 'index'}.html`]
19+
}
20+
21+
const projectFromPath = (path: string[] = []): string | undefined => {
22+
const page = path[0]?.replace(/\.html$/, '')
23+
return page === 'index' ? undefined : page
24+
}
25+
26+
const readDoc = (project: string, doc: LegalDoc): Promise<string | null> =>
27+
readFile(join(LEGAL_DIR, project, `${doc}.md`), 'utf8').catch(() => null)
28+
29+
const listProjects = async (doc: LegalDoc): Promise<string[]> => {
30+
const files = await readdir(LEGAL_DIR, { recursive: true })
31+
return files.filter((file) => file.endsWith(`/${doc}.md`)).map((file) => file.split('/')[0])
32+
}
33+
34+
const titleOf = (markdown: string): string => markdown.match(/^# (.+)$/m)?.[1] ?? ''
35+
36+
const buildIndex = async (doc: LegalDoc): Promise<string> => {
37+
const projects = await listProjects(doc)
38+
const links = await Promise.all(
39+
projects.map(async (project) => {
40+
const markdown = await readDoc(project, doc)
41+
return `- [${titleOf(markdown ?? '')}](/${doc}/${project})`
42+
})
43+
)
44+
return `# ${INDEX_TITLES[doc]}\n\n${links.join('\n')}\n`
45+
}
46+
47+
export const listLegalPagePaths = async (doc: LegalDoc): Promise<string[][]> => {
48+
const projects = await listProjects(doc)
49+
return [toStaticPath(), ...projects.map(toStaticPath)]
50+
}
51+
52+
export const readLegalPage = (doc: LegalDoc, path?: string[]): Promise<string | null> => {
53+
const project = projectFromPath(path)
54+
return project ? readDoc(project, doc) : buildIndex(doc)
55+
}
2056

21-
export const renderLabPage = (markdown: string): string => {
22-
const title = markdown.match(/^# (.+)$/m)?.[1] ?? ''
57+
const renderLegalPage = (markdown: string): string => {
2358
const body = marked.parse(markdown, { async: false })
2459
return `<!doctype html>
2560
<html lang="en">
2661
<head>
2762
<meta charset="utf-8">
2863
<meta name="viewport" content="width=device-width, initial-scale=1">
29-
<title>${title}</title>
64+
<title>${titleOf(markdown)}</title>
3065
<link rel="icon" href="/logo.png">
3166
</head>
3267
<body>
3368
${body}</body>
3469
</html>
3570
`
3671
}
72+
73+
// A route handler skips the root layout, so the page has no site shell.
74+
export const legalPageResponse = (markdown: string | null): Response => {
75+
if (markdown === null) notFound()
76+
77+
return new Response(renderLegalPage(markdown), {
78+
headers: { 'Content-Type': 'text/html; charset=utf-8' },
79+
})
80+
}

0 commit comments

Comments
 (0)