Skip to content

Commit f81d3ff

Browse files
committed
chore: tweaks
1 parent 2054ba2 commit f81d3ff

7 files changed

Lines changed: 80 additions & 12 deletions

File tree

scripts/deployWaf.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ const botPaths = [
4949
]
5050

5151
const excludePrefixes = ['/assets/', '/.well-known/', '/sheep/']
52-
const excludePaths = ['/api/og.png', '/dark.svg', '/favicon.svg', '/light.svg']
52+
const excludePaths = ['/api/og.png', '/dark.svg', '/favicon.svg', '/light.svg', '/og.png']
53+
const excludeWildcards = ['/*.*/*']
5354

5455
const expression = [
5556
`(${[
5657
...excludePrefixes.map((p) => `not starts_with(http.request.uri.path, "${p}")`),
5758
...excludePaths.map((p) => `http.request.uri.path ne "${p}"`),
59+
...excludeWildcards.map((p) => `not (http.request.uri.path wildcard "${p}")`),
5860
].join(
5961
' and ',
6062
)} and (${extensions.map((ext) => `ends_with(http.request.uri.path, "${ext}")`).join(' or ')}))`,

src/md/mod.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ function parseHtmlTagAttributes(tag: string): Record<string, string> {
586586
}
587587

588588
function normalizeMarkdown(content: string, origin?: string, profile?: DetectedProfile): string {
589-
const normalized = profile?.normalize?.(content) ?? content
589+
const normalized = normalizeCodeFencePadding(profile?.normalize?.(content) ?? content)
590590
return (
591591
normalized
592592
// Remove links with no text (e.g. `[](/)`)
@@ -632,3 +632,32 @@ function normalizeMarkdown(content: string, origin?: string, profile?: DetectedP
632632
.trim()
633633
)
634634
}
635+
636+
function normalizeCodeFencePadding(content: string): string {
637+
const lines = content.split('\n')
638+
const normalized: string[] = []
639+
let codeFence: { char: '`' | '~'; length: number; lines: string[] } | undefined
640+
641+
for (const line of lines) {
642+
if (codeFence) {
643+
const closeMatch = line.match(/^(`{3,}|~{3,})\s*$/)
644+
if (closeMatch?.[1]?.startsWith(codeFence.char) && closeMatch[1].length >= codeFence.length) {
645+
while (codeFence.lines[0]?.trim() === '') codeFence.lines.shift()
646+
while (codeFence.lines.at(-1)?.trim() === '') codeFence.lines.pop()
647+
normalized.push(...codeFence.lines, line)
648+
codeFence = undefined
649+
continue
650+
}
651+
codeFence.lines.push(line)
652+
continue
653+
}
654+
655+
const openMatch = line.match(/^(`{3,}|~{3,})/)
656+
if (openMatch?.[1])
657+
codeFence = { char: openMatch[1][0] as '`' | '~', length: openMatch[1].length, lines: [] }
658+
normalized.push(line)
659+
}
660+
661+
if (codeFence) normalized.push(...codeFence.lines)
662+
return normalized.join('\n')
663+
}

src/md/rules/cloudflare.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ description: Review available Cloudflare API token permissions.
4343
expect(result.content).toContain('| User Details Edit | Grants write access to user details. |')
4444
})
4545

46+
test('cloudflare trims blank padding inside first-party markdown code fences', async () => {
47+
const md = create({
48+
fetch: async () =>
49+
new Response('```\n\nlower(http.host) == "www.cloudflare.com"\n\n\n```\n', {
50+
headers: { 'content-type': 'text/markdown; charset=utf-8' },
51+
status: 200,
52+
}),
53+
rules: [cloudflare()],
54+
})
55+
56+
const result = await md.fetch(
57+
'https://developers.cloudflare.com/ruleset-engine/rules-language/functions/',
58+
)
59+
expect(result.ok).toBe(true)
60+
if (!result.ok) return
61+
62+
expect(result.content).toBe('```\nlower(http.host) == "www.cloudflare.com"\n```')
63+
})
64+
4665
test('cloudflare rewrites slashless docs pages to /index.md', async () => {
4766
let request: Request | undefined
4867

src/og.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ async function getElement(env: Cloudflare.Env, db: Database, query: query) {
3131
return playgroundVariant()
3232
}
3333
case 'index': {
34-
const tokensSaved = await getTokensSaved(env, db)
35-
return indexVariant(tokensSaved)
34+
return indexVariant()
3635
}
3736
}
3837
}
@@ -58,18 +57,15 @@ function docsVariant(title: string, description: string | undefined) {
5857
)
5958
}
6059

61-
function indexVariant(tokensSaved: number) {
60+
function indexVariant() {
6261
return (
6362
<div tw="relative flex w-full h-full bg-black text-[#ededed] font-[Geist_Mono] px-[80px] py-[40px]">
64-
<div tw="flex flex-1 flex-col items-center justify-center">
63+
<div tw="flex flex-1 flex-col items-center justify-center pt-[56px]">
6564
<BrandLogo height={56} width={772} />
6665
<div tw="text-[#a1a1a1] text-[54px] mt-[44px] text-center">URL to markdown for agents</div>
67-
</div>
68-
<div tw="absolute right-[80px] bottom-[40px] left-[80px] flex items-end justify-between">
69-
<div tw="text-[#a1a1a1] text-[36px] tracking-[0.08em] uppercase leading-none">
70-
tokens saved
66+
<div tw="bg-[#171717] text-[#ededed] text-[42px] mt-[44px] px-[28px] py-[16px]">
67+
npm i -g curl.md
7168
</div>
72-
<div tw="text-[#ededed] text-[36px] leading-none">{formatNumber(tokensSaved)}</div>
7369
</div>
7470
</div>
7571
)

src/routes/-home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function Home(props: { login?: string | null | undefined }) {
5656
URL to markdown
5757
<br className="hidden md:block" /> for agents
5858
</h1>
59-
<p className="text-gray8 mt-4 text-lg leading-relaxed">
59+
<p className="text-gray8 mt-6 text-lg leading-relaxed">
6060
Turn websites into optimized, low token output to supercharge your context. Works with
6161
every agent.
6262
</p>

test/vitest.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ import { Env } from './env.ts'
1313

1414
const root = path.resolve(import.meta.dirname, '..')
1515

16+
// TODO: remove once porsager/postgres fixes CF polyfill socket teardown.
17+
// https://github.com/cloudflare/workers-sdk/issues/11532
18+
process.on('uncaughtException', (error) => {
19+
if (
20+
error instanceof Error &&
21+
'code' in error &&
22+
(error.code === 'ECONNRESET' || error.code === 'EPIPE')
23+
)
24+
return
25+
throw error
26+
})
27+
1628
const reporters = [isAgent ? 'agent' : 'default']
1729
if (process.env.GITHUB_ACTIONS === 'true') reporters.push('github-actions')
1830

test/workers.setup.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ process.on('unhandledRejection', (reason) => {
99
throw reason
1010
})
1111

12+
process.on('uncaughtException', (error) => {
13+
if (
14+
error instanceof Error &&
15+
'code' in error &&
16+
(error.code === 'ECONNRESET' || error.code === 'EPIPE')
17+
)
18+
return
19+
throw error
20+
})
21+
1222
beforeAll(() => {
1323
server.listen({ onUnhandledRequest: 'error' })
1424
return () => {

0 commit comments

Comments
 (0)