Skip to content

Full text search #3717

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

Merged
merged 76 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
94fee0f
flexsearch
Rich-Harris Feb 4, 2022
71fd627
tweak UI
Rich-Harris Feb 4, 2022
99412ea
tweak
Rich-Harris Feb 4, 2022
eda410c
Update sites/kit.svelte.dev/src/lib/search/Search.svelte
Rich-Harris Feb 4, 2022
9af96b2
Update sites/kit.svelte.dev/src/lib/search/Search.svelte
Rich-Harris Feb 4, 2022
43035c8
work around marked global state sharing
Rich-Harris Feb 4, 2022
26fcf8c
Merge branch 'flexsearch' of github.com:sveltejs/kit into flexsearch
Rich-Harris Feb 4, 2022
7380a71
include migrating/faqs
Rich-Harris Feb 4, 2022
b06ccc8
fade in search bar
Rich-Harris Feb 4, 2022
894a02b
prevent blocking
Rich-Harris Feb 4, 2022
f4e3dd2
remove commented out nav items
Rich-Harris Feb 4, 2022
b8a2fcf
ui tweaks
Rich-Harris Feb 4, 2022
a78c97d
close search box on tapping modal background
Rich-Harris Feb 4, 2022
df94a96
update site-kit
Rich-Harris Feb 4, 2022
f217100
tweak style
Rich-Harris Feb 4, 2022
5b9d019
fix position:fixed css glitch by separating components
Rich-Harris Feb 4, 2022
a47fcd2
fix mobile sizing
Rich-Harris Feb 4, 2022
3ce2ac1
tidy up
Rich-Harris Feb 4, 2022
8f67e87
close on backspace
Rich-Harris Feb 4, 2022
9e194fd
close with backspace
Rich-Harris Feb 4, 2022
9cb181c
add search icon, show ctrl-key on windows
Rich-Harris Feb 4, 2022
6637f80
use ctrl key on windows
Rich-Harris Feb 4, 2022
9c303f5
reinstate links
Rich-Harris Feb 4, 2022
9ad78c4
configure typescript
Rich-Harris Feb 5, 2022
c11690d
rudimentary recent searches
Rich-Harris Feb 5, 2022
69bc586
various fixes
Rich-Harris Feb 5, 2022
27bfcc4
add close button
Rich-Harris Feb 5, 2022
5980cb9
distinguish between tab and arrow key
Rich-Harris Feb 5, 2022
b72da82
explanation
Rich-Harris Feb 5, 2022
15834e9
add delete button
Rich-Harris Feb 5, 2022
1bc6db6
remove unused handler
Rich-Harris Feb 5, 2022
f28a4f6
tweak faq page
Rich-Harris Feb 5, 2022
92f1f3c
oops
Rich-Harris Feb 5, 2022
af4c8da
fix FAQ links
Rich-Harris Feb 5, 2022
847a396
fix links
Rich-Harris Feb 5, 2022
1ab4c09
select first result on enter
Rich-Harris Feb 5, 2022
b6121be
multi-page docs
Rich-Harris Feb 7, 2022
c84da40
Update sites/kit.svelte.dev/src/lib/search/Search.svelte
Rich-Harris Feb 7, 2022
c507bc8
Update sites/kit.svelte.dev/src/lib/search/Search.svelte
Rich-Harris Feb 7, 2022
2a3f12c
Update sites/kit.svelte.dev/src/routes/__layout.svelte
Rich-Harris Feb 7, 2022
64270f1
Update sites/kit.svelte.dev/src/lib/search/Search.svelte
Rich-Harris Feb 7, 2022
cd1747c
explain why we prevent default on spacebar press
Rich-Harris Feb 7, 2022
64f1e39
Merge branch 'flexsearch' of github.com:sveltejs/kit into flexsearch
Rich-Harris Feb 7, 2022
22018d1
move delete button out of <a>
Rich-Harris Feb 7, 2022
f4bc81e
wrap <Search> in <li>
Rich-Harris Feb 7, 2022
71dee8e
move <SearchBox> inside <main>
Rich-Harris Feb 7, 2022
94a412b
use position:fixed on body to prevent scroll while modal is open
Rich-Harris Feb 7, 2022
f036874
hopefully fix safari layout
Rich-Harris Feb 7, 2022
2ac33f1
use label instead of aria-label
Rich-Harris Feb 7, 2022
82fa4b4
use a heading instead of an li
Rich-Harris Feb 7, 2022
11618c7
prerender TOC data
Rich-Harris Feb 7, 2022
50172e2
err hmmm
Rich-Harris Feb 7, 2022
9f0cdd8
fix some contrast ratios, add aria-describedby to input
Rich-Harris Feb 7, 2022
a99a2d3
fix prerendering
Rich-Harris Feb 7, 2022
672ab51
make edit link clickable
Rich-Harris Feb 7, 2022
40c2026
add aria-live region for no results
Rich-Harris Feb 7, 2022
e2c36aa
focus body when closing modal
Rich-Harris Feb 7, 2022
5cb0d43
fix search result links
Rich-Harris Feb 8, 2022
a2677d8
update tsconfig
Rich-Harris Feb 8, 2022
a9e4205
prevent nav links overlapping with search bar
Rich-Harris Feb 8, 2022
b8ee5ca
slim down responses
Rich-Harris Feb 8, 2022
c37bddc
add prev/next links
Rich-Harris Feb 8, 2022
2080e20
show contents as footer on mobile
Rich-Harris Feb 8, 2022
8205615
fold migrating into main docs
Rich-Harris Feb 9, 2022
e210326
merge master
Rich-Harris Feb 9, 2022
4916944
fix build-blocking bugs
Rich-Harris Feb 9, 2022
4749494
/docs/sections.json -> /docs.json
Rich-Harris Feb 9, 2022
4b697af
update config
Rich-Harris Feb 9, 2022
cda29b3
remove unused file (merge conflict)
Rich-Harris Feb 9, 2022
1920788
update docs
Rich-Harris Feb 9, 2022
84d9b2a
update internal links
Rich-Harris Feb 9, 2022
072818e
fix links
Rich-Harris Feb 9, 2022
635ae95
fix gradient overlay
Rich-Harris Feb 9, 2022
666c155
Merge branch 'master' into flexsearch
Rich-Harris Feb 9, 2022
c315589
update lockfile
Rich-Harris Feb 9, 2022
fdbd9d5
give default template a name, for sake of cloudflare deployment
Rich-Harris Feb 9, 2022
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
22 changes: 18 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion sites/kit.svelte.dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
"devDependencies": {
"@sveltejs/adapter-auto": "workspace:*",
"@sveltejs/kit": "workspace:*",
"@sveltejs/site-kit": "^2.0.0",
"@sveltejs/site-kit": "^2.0.2",
"@types/node": "^16.6.1",
"flexsearch": "^0.7.21",
"marked": "^4.0.5",
"prism-svelte": "^0.4.7",
"prismjs": "^1.26.0",
"svelte": "^3.43.0",
"typescript": "^4.5.5",
"vite-imagetools": "^4.0.3"
},
"type": "module"
Expand Down
68 changes: 68 additions & 0 deletions sites/kit.svelte.dev/src/lib/actions/focus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/** @param {HTMLElement} node */
export function focusable_children(node) {
const nodes = Array.from(
node.querySelectorAll(
'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])'
)
);

const index = nodes.indexOf(document.activeElement);

const update = (d) => {
let i = index + d;
i += nodes.length;
i %= nodes.length;

// @ts-expect-error
nodes[i].focus();
};

return {
/** @param {string} [selector] */
next: (selector) => {
const reordered = [...nodes.slice(index + 1), ...nodes.slice(0, index + 1)];

for (let i = 0; i < reordered.length; i += 1) {
if (!selector || reordered[i].matches(selector)) {
reordered[i].focus();
return;
}
}
},
/** @param {string} [selector] */
prev: (selector) => {
const reordered = [...nodes.slice(index + 1), ...nodes.slice(0, index + 1)];

for (let i = reordered.length - 2; i >= 0; i -= 1) {
if (!selector || reordered[i].matches(selector)) {
reordered[i].focus();
return;
}
}
},
update
};
}

export function trap(node) {
const handle_keydown = (e) => {
if (e.key === 'Tab') {
e.preventDefault();

const group = focusable_children(node);
if (e.shiftKey) {
group.prev();
} else {
group.next();
}
}
};

node.addEventListener('keydown', handle_keydown);

return {
destroy: () => {
node.removeEventListener('keydown', handle_keydown);
}
};
}
114 changes: 48 additions & 66 deletions sites/kit.svelte.dev/src/lib/docs/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fs from 'fs';
import { marked } from 'marked';
import PrismJS from 'prismjs';

import 'prismjs/components/prism-bash.js';
import 'prismjs/components/prism-diff.js';
import 'prismjs/components/prism-typescript.js';
import 'prism-svelte';
import { extract_frontmatter, transform } from './markdown';

const languages = {
bash: 'bash',
Expand Down Expand Up @@ -42,67 +42,63 @@ function parse(markdown, file) {

const slug = slugify(metadata.title);

const headings = [, slug];
const headings = [];
const sections = [];

let section;

marked.use({
renderer: {
heading(html, level) {
const title = html
.replace(/&quot;/g, '"')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>');

const normalized = slugify(title);

headings[level - 1] = normalized;
headings.length = level;

const slug = headings.filter(Boolean).join('-');

if (level === 3) {
section = {
title,
slug,
sections: []
};

sections.push(section);
} else if (level === 4) {
section.sections.push({
title,
slug
});
} else {
throw new Error(`Unexpected <h${level}> in ${file}`);
}
const content = transform(body, {
heading(html, level) {
const title = html
.replace(/&quot;/g, '"')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>');

return `<h${level} id="${slug}">${html}</h${level}>`;
},
code(source, lang) {
// for no good reason at all, marked replaces tabs with spaces
source = source.replace(/^( )+/gm, (match) => {
let tabs = '';
for (let i = 0; i < match.length; i += 4) {
tabs += '\t';
}
return tabs;
});
const normalized = slugify(title);

headings[level - 1] = normalized;
headings.length = level;

const slug = headings.filter(Boolean).join('-');

const plang = languages[lang];
const highlighted = plang
? PrismJS.highlight(source, PrismJS.languages[plang], lang)
: source.replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' }[c]));
if (level === 3) {
section = {
title,
slug,
sections: []
};

return `<div class="code-block"><pre class='language-${plang}'><code>${highlighted}</code></pre></div>`;
sections.push(section);
} else if (level === 4) {
section.sections.push({
title,
slug
});
} else {
throw new Error(`Unexpected <h${level}> in ${file}`);
}

return `<h${level} id="${slug}">${html}</h${level}>`;
},
code(source, lang) {
// for no good reason at all, marked replaces tabs with spaces
source = source.replace(/^( )+/gm, (match) => {
let tabs = '';
for (let i = 0; i < match.length; i += 4) {
tabs += '\t';
}
return tabs;
});

const plang = languages[lang];
const highlighted = plang
? PrismJS.highlight(source, PrismJS.languages[plang], lang)
: source.replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' }[c]));

return `<div class="code-block"><pre class='language-${plang}'><code>${highlighted}</code></pre></div>`;
}
});

const content = marked(body);

return {
slug,
title: metadata.title,
Expand All @@ -111,21 +107,7 @@ function parse(markdown, file) {
};
}

function extract_frontmatter(markdown) {
const match = /---\r?\n([\s\S]+?)\r?\n---/.exec(markdown);
const frontmatter = match[1];
const body = markdown.slice(match[0].length);

const metadata = {};
frontmatter.split('\n').forEach((pair) => {
const i = pair.indexOf(':');
metadata[pair.slice(0, i).trim()] = pair.slice(i + 1).trim();
});

return { metadata, body };
}

function slugify(title) {
export function slugify(title) {
return title
.toLowerCase()
.replace(/[^a-z0-9-$]/g, '-')
Expand Down
Loading