Skip to content

Commit eb680d9

Browse files
authored
Merge branch 'main' into fil/save-search-query
2 parents 1e75697 + f6b9ab5 commit eb680d9

File tree

11 files changed

+254
-194
lines changed

11 files changed

+254
-194
lines changed

docs/markdown.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The front matter supports the following options:
1818
- **title** — the page title; defaults to the (first) first-level heading of the page, if any
1919
- **toc** — if false, disables the [table of contents](./config#toc)
2020
- **index** — whether to index this page if [search](./search) is enabled; defaults to true for listed pages
21+
- **keywords** - additional words to index for [search](./search); boosted at the same weight as the title
2122
- **draft** — whether to skip this page during build; drafts are also not listed in the default sidebar
2223

2324
## Headings

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"test": "concurrently npm:test:mocha npm:test:tsc npm:test:lint npm:test:prettier",
3030
"test:coverage": "c8 yarn test:mocha",
3131
"test:mocha": "rimraf --glob test/.observablehq/cache test/input/build/*/.observablehq/cache && cross-env OBSERVABLE_TELEMETRY_DISABLE=1 TZ=America/Los_Angeles tsx --no-warnings=ExperimentalWarning ./node_modules/mocha/bin/mocha.js -p 'test/**/*-test.*'",
32+
"test:mocha:serial": "rimraf --glob test/.observablehq/cache test/input/build/*/.observablehq/cache && cross-env OBSERVABLE_TELEMETRY_DISABLE=1 TZ=America/Los_Angeles tsx --no-warnings=ExperimentalWarning ./node_modules/mocha/bin/mocha.js 'test/**/*-test.*'",
3233
"test:lint": "eslint src test --max-warnings=0",
3334
"test:prettier": "prettier --check src test",
3435
"test:tsc": "tsc --noEmit",
@@ -108,6 +109,7 @@
108109
"mocha": "^10.2.0",
109110
"prettier": "^3.0.3 <3.1",
110111
"rimraf": "^5.0.5",
112+
"tempy": "^3.1.0",
111113
"typescript": "^5.2.2",
112114
"undici": "^5.27.2"
113115
},

src/client/pre.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export function enableCopyButtons() {
1515
}
1616
}
1717

18-
async function copy({currentTarget}) {
19-
await navigator.clipboard.writeText(currentTarget.parentElement.textContent.trimEnd());
18+
async function copy({currentTarget: target}) {
19+
await navigator.clipboard.writeText(target.nextElementSibling.textContent.trim());
20+
const [animation] = target.getAnimations({subtree: true});
21+
if (animation) animation.currentTime = 0;
22+
target.classList.add("observablehq-pre-copied");
23+
target.addEventListener("animationend", () => target.classList.remove("observablehq-pre-copied"), {once: true});
2024
}

src/client/stdlib/fileAttachment.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ async function dsv(file, delimiter, {array = false, typed = false} = {}) {
2828
}
2929

3030
export class AbstractFile {
31-
constructor(name, mimeType) {
32-
Object.defineProperty(this, "name", {value: name, enumerable: true});
33-
if (mimeType !== undefined) Object.defineProperty(this, "mimeType", {value: mimeType + "", enumerable: true});
31+
constructor(name, mimeType = "application/octet-stream") {
32+
Object.defineProperty(this, "name", {value: `${name}`, enumerable: true});
33+
Object.defineProperty(this, "mimeType", {value: `${mimeType}`, enumerable: true});
3434
}
3535
async blob() {
3636
return (await remote_fetch(this)).blob();
@@ -100,7 +100,7 @@ class FileAttachmentImpl extends AbstractFile {
100100
Object.defineProperty(this, "_url", {value: url});
101101
}
102102
async url() {
103-
return (await this._url) + "";
103+
return `${await this._url}`;
104104
}
105105
}
106106

src/convert.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ export async function convert(
6464
if (await maybeFetch(path, force, effects)) {
6565
start = Date.now();
6666
s = clack.spinner();
67-
s.start(`Downloading ${bold(file.name)}`);
67+
s.start(`Downloading ${bold(path)}`);
6868
const response = await fetch(file.download_url);
6969
if (!response.ok) throw new Error(`error fetching ${file.download_url}: ${response.status}`);
7070
const buffer = Buffer.from(await response.arrayBuffer());
71-
s.stop(`Downloaded ${bold(file.name)} ${faint(`in ${(Date.now() - start).toLocaleString("en-US")}ms`)}`);
71+
s.stop(`Downloaded ${bold(path)} ${faint(`in ${(Date.now() - start).toLocaleString("en-US")}ms`)}`);
7272
await effects.prepareOutput(path);
7373
await effects.writeFile(path, buffer);
7474
await effects.touch(path, file.create_time);

src/preview.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ function handleWatch(socket: WebSocket, req: IncomingMessage, {root, style}: Con
357357

358358
async function hello({path: initialPath, hash: initialHash}: {path: string; hash: string}): Promise<void> {
359359
if (markdownWatcher || attachmentWatcher) throw new Error("already watching");
360-
path = initialPath;
360+
path = decodeURIComponent(initialPath);
361361
if (!(path = normalize(path)).startsWith("/")) throw new Error("Invalid path: " + initialPath);
362362
if (path.endsWith("/")) path += "index";
363363
path += ".md";
@@ -451,7 +451,7 @@ function diffCode(oldCode: Map<string, string>, newCode: Map<string, string>): C
451451
return patch;
452452
}
453453

454-
type FileDeclaration = {name: string; mimeType: string | null; path: string};
454+
type FileDeclaration = {name: string; mimeType?: string; path: string};
455455
type FilePatch = {removed: string[]; added: FileDeclaration[]};
456456

457457
function diffFiles(oldFiles: Map<string, string>, newFiles: Map<string, string>): FilePatch {
@@ -463,7 +463,7 @@ function diffFiles(oldFiles: Map<string, string>, newFiles: Map<string, string>)
463463
}
464464
for (const [name, path] of newFiles) {
465465
if (oldFiles.get(name) !== path) {
466-
patch.added.push({name, mimeType: mime.getType(name), path});
466+
patch.added.push({name, mimeType: mime.getType(name) ?? undefined, path});
467467
}
468468
}
469469
return patch;

src/render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function renderFiles(files: Iterable<string>, resolve: (name: string) => string)
8383
function renderFile(name: string, resolve: (name: string) => string): string {
8484
return `\nregisterFile(${JSON.stringify(name)}, ${JSON.stringify({
8585
name,
86-
mimeType: mime.getType(name),
86+
mimeType: mime.getType(name) ?? undefined,
8787
path: resolve(name)
8888
})});`;
8989
}

src/style/global.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ h6 {
4040
margin-top: 0;
4141
margin-bottom: 0.25rem;
4242
scroll-margin-top: 1rem;
43+
text-wrap: balance;
4344
}
4445

4546
h2 + p,

src/style/layout.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,35 @@
422422
align-items: center;
423423
}
424424

425+
.observablehq-pre-copied::before {
426+
content: "Copied!";
427+
position: absolute;
428+
right: calc(100% + 0.25rem);
429+
background: var(--theme-background-alt);
430+
color: var(--theme-green);
431+
font: var(--font-small);
432+
border-radius: 4px;
433+
padding: 4px 8px;
434+
pointer-events: none;
435+
animation-name: observablehq-pre-copied;
436+
animation-duration: 250ms;
437+
animation-direction: alternate;
438+
animation-iteration-count: 2;
439+
}
440+
441+
@keyframes observablehq-pre-copied {
442+
0% {
443+
opacity: 0;
444+
transform: translateX(0.5rem);
445+
}
446+
50% {
447+
opacity: 1;
448+
}
449+
100% {
450+
transform: translateX(0);
451+
}
452+
}
453+
425454
.observablehq-pre-container[data-copy] .observablehq-pre-copy,
426455
.observablehq-pre-container:hover .observablehq-pre-copy,
427456
.observablehq-pre-container .observablehq-pre-copy:focus {

0 commit comments

Comments
 (0)