Skip to content

Commit 27bf705

Browse files
committed
ci: deploy docs to github pages
1 parent 92463af commit 27bf705

3 files changed

Lines changed: 93 additions & 2 deletions

File tree

.github/workflows/pages.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Deploy Docs (GitHub Pages)
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
workflow_dispatch: {}
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: "pages"
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Deno
25+
uses: denoland/setup-deno@v2
26+
with:
27+
deno-version: v2.x
28+
29+
- name: Test
30+
run: deno task test
31+
32+
- name: Build docs bundle
33+
run: deno task docs:bundle
34+
35+
- name: Configure Pages
36+
uses: actions/configure-pages@v5
37+
38+
- name: Upload artifact
39+
uses: actions/upload-pages-artifact@v3
40+
with:
41+
path: docs
42+
43+
deploy:
44+
needs: build
45+
runs-on: ubuntu-latest
46+
environment:
47+
name: github-pages
48+
url: ${{ steps.deployment.outputs.page_url }}
49+
steps:
50+
- name: Deploy to GitHub Pages
51+
id: deployment
52+
uses: actions/deploy-pages@v4

docs/app.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,23 @@ const groupByStart = (entities) => {
301301
const display = [];
302302
for (const s of starts) {
303303
const arr = map.get(s) ?? [];
304-
arr.sort((a, b) => (b.end - a.end) || String(a.kind).localeCompare(b.kind));
304+
// For the hovercard, keep "most informative" (longest) first.
305+
arr.sort((a, b) =>
306+
(b.end - b.start) - (a.end - a.start) ||
307+
(b.end - a.end) ||
308+
String(a.kind).localeCompare(b.kind)
309+
);
305310
if (!arr.length) continue;
306311
groups.push(arr);
307-
display.push(arr[0]); // representative for annotation
312+
313+
// For annotation, prefer the smallest (shortest) match so we don't hide
314+
// inner groups (e.g. CC + 4x quantity chunks).
315+
const smallest = [...arr].sort((a, b) =>
316+
(a.end - a.start) - (b.end - b.start) ||
317+
(a.end - b.end) ||
318+
String(a.kind).localeCompare(b.kind)
319+
)[0];
320+
display.push(smallest);
308321
}
309322
return { map, groups, display };
310323
};

tests/CreditCard.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,29 @@ Deno.test("Credit card invalid does not parse", () => {
3434
assertEquals(res.value, []);
3535
}
3636
});
37+
38+
Deno.test("Duckling extracts CC + 4-digit groups (step shortest)", () => {
39+
const text = "CC 4242 4242 4242 4242";
40+
const res = Duckling().extract({ text, index: 0 });
41+
42+
assertEquals(res.success, true);
43+
if (!res.success) return;
44+
45+
assertEquals(
46+
res.value.some((e) =>
47+
e.kind === "credit_card" && e.text === "4242 4242 4242 4242"
48+
),
49+
true,
50+
);
51+
52+
const groups = res.value.filter((e) =>
53+
e.kind === "quantity" && e.text === "4242"
54+
);
55+
assertEquals(groups.length, 4);
56+
assertEquals(groups.map((e) => [e.start, e.end]), [
57+
[3, 7],
58+
[8, 12],
59+
[13, 17],
60+
[18, 22],
61+
]);
62+
});

0 commit comments

Comments
 (0)