Repository navigation
fix(seo): include curated showcase detail pages in sitemap #1476
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
Open
tannerlinsley
wants to merge
1
commit into
main
Choose a base branch
from
taren/sitemap-curated-showcases
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { and, eq } from 'drizzle-orm' | ||
| import { db, isDatabaseConfigured } from '~/db/client' | ||
| import { showcases } from '~/db/schema' | ||
|
|
||
| export async function getShowcaseSitemapEntries() { | ||
| if (process.env.NODE_ENV === 'development' && !(await isDatabaseConfigured())) | ||
| return [] | ||
|
|
||
| const projects = await db | ||
| .select({ id: showcases.id }) | ||
| .from(showcases) | ||
| .where( | ||
| and( | ||
| eq(showcases.status, 'approved'), | ||
| eq(showcases.placement, 'showcase'), | ||
| ), | ||
| ) | ||
|
|
||
| return projects.map(({ id }) => ({ path: `/showcase/${id}` })) | ||
| } |
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,82 @@ | ||
| import assert from 'node:assert/strict' | ||
| import test from 'node:test' | ||
| import { mkdtemp, mkdir, rm } from 'node:fs/promises' | ||
| import { resolve, join } from 'node:path' | ||
| import { pathToFileURL } from 'node:url' | ||
| import { randomUUID } from 'node:crypto' | ||
| import { build } from 'esbuild' | ||
| import postgres from 'postgres' | ||
| import { SHOWCASE_STATUSES, SHOWCASE_PLACEMENTS } from '../src/db/types' | ||
|
|
||
| const databaseUrl = process.env.SHOWCASE_SITEMAP_TEST_DATABASE_URL | ||
|
|
||
| test( | ||
| 'sitemap includes only approved curated showcases from the database', | ||
| { skip: !databaseUrl }, | ||
| async () => { | ||
| assert.ok(databaseUrl) | ||
| const url = new URL(databaseUrl) | ||
| assert.equal(url.hostname, '127.0.0.1') | ||
| assert.match(url.pathname, /^\/watch_sitemap_/) | ||
| const sql = postgres(databaseUrl, { max: 1 }) | ||
| await mkdir('node_modules/.cache', { recursive: true }) | ||
| const directory = await mkdtemp( | ||
| resolve('node_modules/.cache/sitemap-test-'), | ||
| ) | ||
| let createdTable = false | ||
| let closeDatabase: (() => Promise<void>) | undefined | ||
| try { | ||
| await sql`CREATE TABLE showcases (id uuid PRIMARY KEY, status text NOT NULL, placement text NOT NULL)` | ||
| createdTable = true | ||
| let expectedId = '' | ||
| for (const status of SHOWCASE_STATUSES) { | ||
| for (const placement of SHOWCASE_PLACEMENTS) { | ||
| const id = randomUUID() | ||
| await sql`INSERT INTO showcases VALUES (${id}, ${status}, ${placement})` | ||
| if (status === 'approved' && placement === 'showcase') expectedId = id | ||
| } | ||
| } | ||
| const output = join(directory, 'query.mjs') | ||
| await build({ | ||
| stdin: { | ||
| contents: `export { getShowcaseSitemapEntries } from './src/utils/showcase-sitemap.server'; export { closeDatabase } from 'fixture:db';`, | ||
| resolveDir: process.cwd(), | ||
| loader: 'ts', | ||
| }, | ||
| outfile: output, | ||
| bundle: true, | ||
| platform: 'node', | ||
| format: 'esm', | ||
| packages: 'external', | ||
| plugins: [ | ||
| { | ||
| name: 'isolated-local-database', | ||
| setup(builder) { | ||
| builder.onResolve( | ||
| { filter: /^(~\/db\/client|fixture:db)$/ }, | ||
| () => ({ path: 'db', namespace: 'fixture' }), | ||
| ) | ||
| builder.onLoad({ filter: /.*/, namespace: 'fixture' }, () => ({ | ||
| contents: `import postgres from 'postgres'; import { drizzle } from 'drizzle-orm/postgres-js'; const client = postgres(process.env.SHOWCASE_SITEMAP_TEST_DATABASE_URL, { max: 1 }); export const db = drizzle(client); export const isDatabaseConfigured = async () => true; export const closeDatabase = () => client.end();`, | ||
| loader: 'js', | ||
| resolveDir: process.cwd(), | ||
| })) | ||
| }, | ||
| }, | ||
| ], | ||
| }) | ||
| const query = await import(pathToFileURL(output).href) | ||
| closeDatabase = query.closeDatabase | ||
| assert.deepEqual(await query.getShowcaseSitemapEntries(), [ | ||
| { path: `/showcase/${expectedId}` }, | ||
| ]) | ||
| await sql`UPDATE showcases SET placement = 'private' WHERE id = ${expectedId}` | ||
| assert.deepEqual(await query.getShowcaseSitemapEntries(), []) | ||
| } finally { | ||
| await closeDatabase?.() | ||
| if (createdTable) await sql`DROP TABLE showcases` | ||
| await sql.end() | ||
| await rm(directory, { recursive: true, force: true }) | ||
| } | ||
| }, | ||
| ) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep showcase database failures from taking down the sitemap.
If the showcase query rejects or the database is unavailable, this promise rejects
Promise.all. The/sitemap.xmlhandler then fails instead of returning the existing library, blog, and chart URLs. Catch and log the showcase failure, then return an empty showcase list. The charts loader already uses a fallback for its own failure path. (raw.githubusercontent.com)