Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci-website-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
- name: Validate llms.txt links
run: pnpm --filter @comfyorg/website validate:llms-txt-links

- name: Validate advertised markdown copies
run: pnpm --filter @comfyorg/website validate:markdown-alternates
Comment thread
MaanilVerma marked this conversation as resolved.
Resolved

- name: Check internal links end with a slash
run: pnpm --filter @comfyorg/website check:link-slashes

Expand Down Expand Up @@ -77,6 +80,7 @@ jobs:
fi
pnpm --filter @comfyorg/website build
pnpm --filter @comfyorg/website check:link-slashes
pnpm --filter @comfyorg/website validate:markdown-alternates
Comment thread
MaanilVerma marked this conversation as resolved.
Resolved
if [ -d apps/website/dist/workshop ]; then
echo "::error title=Workshop leaked into a release build::apps/website/dist/workshop exists with WORKSHOP_IN_BUILD=0. The retired Workshop routes must not deploy. See apps/website/src/integrations/workshop-release-gate.ts."
exit 1
Expand Down
1 change: 1 addition & 0 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"check:models-html": "tsx ./scripts/check-models-html.ts",
"list:models-pages": "tsx ./scripts/list-models-pages.ts",
"validate:llms-txt-links": "tsx ./scripts/validate-llms-txt-links.ts",
"validate:markdown-alternates": "tsx ./scripts/validate-markdown-alternates.ts",
"indexnow:submit": "tsx ./scripts/indexnow-submit.ts",
"check:link-slashes": "tsx ./scripts/check-internal-link-slashes.ts",
"workshop:generate": "tsx ./scripts/generate-workshop-models.ts",
Expand Down
23 changes: 5 additions & 18 deletions apps/website/scripts/check-hreflang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,21 @@
*/
import type { Alternate } from '@/utils/hreflangRoutes'

import { existsSync, readdirSync, readFileSync } from 'node:fs'
import { join, relative, sep } from 'node:path'
import { existsSync, readFileSync } from 'node:fs'
import { join, relative } from 'node:path'

import {
auditBuiltSite,
routeOfHref,
sitemapChunkNames
} from '@/utils/hreflangAudit'

import { htmlFiles, routeOf } from './dist-html'

const DIST = join(process.cwd(), 'dist')
const PUBLIC = join(process.cwd(), 'public')
const ORIGIN = 'https://comfy.org'

function htmlFiles(dir: string): string[] {
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
const full = join(dir, entry.name)
if (entry.isDirectory()) return htmlFiles(full)
return entry.name.endsWith('.html') ? [full] : []
})
}

/** `dist/zh-CN/about/index.html` -> `/zh-CN/about/` */
function routeOf(file: string): string {
const rel = relative(DIST, file).split(sep).join('/')
const withoutIndex = rel.replace(/index\.html$/, '')
return `/${withoutIndex}`.replace(/\/{2,}/g, '/')
}

function alternatesIn(html: string): Alternate[] {
const out: Alternate[] = []
const re = /<link\s+rel="alternate"\s+hreflang="([^"]+)"\s+href="([^"]+)"/g
Expand Down Expand Up @@ -98,7 +85,7 @@ const pages = new Map<string, Alternate[]>()
const canonicals = new Map<string, string>()

for (const file of files) {
const route = routeOf(file)
const route = routeOf(DIST, file)
const html = readFileSync(file, 'utf-8')
const alternates = alternatesIn(html)
pages.set(route, alternates)
Expand Down
12 changes: 3 additions & 9 deletions apps/website/scripts/check-internal-link-slashes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,17 @@
* slash, or through the www host. Both reach the page only via a second
* address, which splits its signals until a crawler settles on the canonical.
*/
import { existsSync, readdirSync, readFileSync } from 'node:fs'
import { existsSync, readFileSync } from 'node:fs'
import { join, relative, sep } from 'node:path'

import { aliasHostHrefs, slashlessPageHrefs } from '@/utils/internalLinkSlashes'

import { htmlFiles } from './dist-html'

const DIST = join(process.cwd(), 'dist')
const ORIGINS = ['https://comfy.org']
const ALIAS_ORIGINS = ['https://www.comfy.org']

function htmlFiles(dir: string): string[] {
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
const full = join(dir, entry.name)
if (entry.isDirectory()) return htmlFiles(full)
return entry.name.endsWith('.html') ? [full] : []
})
}

if (!existsSync(DIST)) {
console.error(`[link-slashes] ${DIST} does not exist; build first.`)
process.exit(1)
Expand Down
42 changes: 42 additions & 0 deletions apps/website/scripts/dist-html.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { beforeAll, afterAll, describe, expect, it } from 'vitest'

import { htmlFiles, isFileWithExactCase, routeOf } from './dist-html'

let root: string

beforeAll(async () => {
root = await mkdtemp(join(tmpdir(), 'dist-html-'))
await mkdir(join(root, 'zh-CN', 'about'), { recursive: true })
await writeFile(join(root, 'index.html'), '')
await writeFile(join(root, 'searchindex.html'), '')
await writeFile(join(root, 'zh-CN', 'about', 'index.html'), '')
await writeFile(join(root, 'zh-CN', 'cli.md'), '')
})

afterAll(() => rm(root, { recursive: true, force: true }))

describe('htmlFiles and routeOf', () => {
it('lists every built page as its route', () => {
expect(
htmlFiles(root)
.map((file) => routeOf(root, file))
.sort()
).toEqual(['/', '/searchindex.html', '/zh-CN/about/'])
})
})

describe('isFileWithExactCase', () => {
it.for([
{ path: '/zh-CN/cli.md', exists: true },
{ path: '/zh-CN/CLI.md', exists: false },
{ path: '/ZH-cn/cli.md', exists: false },
{ path: '/zh-CN/missing.md', exists: false },
{ path: '/zh-CN', exists: false },
{ path: '/', exists: false }
])('$path exists: $exists', ({ path, exists }) => {
expect(isFileWithExactCase(root, path)).toBe(exists)
})
})
38 changes: 38 additions & 0 deletions apps/website/scripts/dist-html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { readdirSync } from 'node:fs'
import { join, relative, sep } from 'node:path'

/** Every `.html` file under `dir`, recursively. Throws when `dir` is missing. */
export function htmlFiles(dir: string): string[] {
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
const full = join(dir, entry.name)
if (entry.isDirectory()) return htmlFiles(full)
return entry.name.endsWith('.html') ? [full] : []
})
}

/** `<root>/zh-CN/about/index.html` -> `/zh-CN/about/` */
export function routeOf(root: string, file: string): string {
const rel = relative(root, file).split(sep).join('/')
const withoutIndex = rel.replace(/(^|\/)index\.html$/, '$1')
return `/${withoutIndex}`.replace(/\/{2,}/g, '/')
}

/**
* Whether `path` (`/zh-CN/cli.md`) names a file under `root` with this exact
* case. `existsSync` ignores case on macOS and Windows; the Linux CI and the
* CDN do not.
*/
export function isFileWithExactCase(root: string, path: string): boolean {
const segments = path.split('/').filter(Boolean)
return (
segments.length > 0 &&
segments.every((segment, index) => {
const entry = readdirSync(join(root, ...segments.slice(0, index)), {
withFileTypes: true
}).find(({ name }) => name === segment)
return index === segments.length - 1
? entry?.isFile() === true
: entry?.isDirectory() === true
})
)
}
57 changes: 57 additions & 0 deletions apps/website/scripts/validate-markdown-alternates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Fails when too few built pages advertise a markdown copy, or a page
* advertises one that was not built or whose front matter does not name that
* page as its canonical.
*/
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'

import {
advertisementShortfall,
auditMarkdownAlternates
} from '@/utils/markdownAlternateAudit'

import { htmlFiles, isFileWithExactCase, routeOf } from './dist-html'

const DIST = join(process.cwd(), 'dist')
const ORIGIN = 'https://comfy.org'

function readTwin(path: string): string | undefined {
return isFileWithExactCase(DIST, path)
? readFileSync(join(DIST, path), 'utf-8')
: undefined
}

if (!existsSync(DIST)) {
console.error(`[markdown-alternates] ${DIST} does not exist; build first.`)
process.exit(1)
}

const pages = htmlFiles(DIST).map((file) => ({
route: routeOf(DIST, file),
html: readFileSync(file, 'utf-8')
}))
const { advertised, canonicalChecked, problems } = auditMarkdownAlternates(
pages,
readTwin,
ORIGIN
)

const shortfall = advertisementShortfall(advertised, pages.length)
if (shortfall !== undefined) {
console.error(`[markdown-alternates] ${shortfall}`)
process.exit(1)
}

if (problems.length > 0) {
console.error(
`[markdown-alternates] ${problems.length} of ${advertised} advertised markdown copies are broken:`
)
for (const problem of problems) console.error(` ${problem}`)
process.exit(1)
}

console.warn(
`[markdown-alternates] ${advertised} of ${pages.length} pages advertise a markdown copy, and every copy exists. ` +
`${canonicalChecked} name their page as canonical; ${advertised - canonicalChecked} pages emit no canonical to compare.`
)
Loading
Loading