Skip to content

Commit

Permalink
Merge branch 'main' into fil/save-search-query
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil authored Mar 4, 2024
2 parents 1e75697 + f6b9ab5 commit eb680d9
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 194 deletions.
1 change: 1 addition & 0 deletions docs/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The front matter supports the following options:
- **title** — the page title; defaults to the (first) first-level heading of the page, if any
- **toc** — if false, disables the [table of contents](./config#toc)
- **index** — whether to index this page if [search](./search) is enabled; defaults to true for listed pages
- **keywords** - additional words to index for [search](./search); boosted at the same weight as the title
- **draft** — whether to skip this page during build; drafts are also not listed in the default sidebar

## Headings
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"test": "concurrently npm:test:mocha npm:test:tsc npm:test:lint npm:test:prettier",
"test:coverage": "c8 yarn test:mocha",
"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.*'",
"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.*'",
"test:lint": "eslint src test --max-warnings=0",
"test:prettier": "prettier --check src test",
"test:tsc": "tsc --noEmit",
Expand Down Expand Up @@ -108,6 +109,7 @@
"mocha": "^10.2.0",
"prettier": "^3.0.3 <3.1",
"rimraf": "^5.0.5",
"tempy": "^3.1.0",
"typescript": "^5.2.2",
"undici": "^5.27.2"
},
Expand Down
8 changes: 6 additions & 2 deletions src/client/pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export function enableCopyButtons() {
}
}

async function copy({currentTarget}) {
await navigator.clipboard.writeText(currentTarget.parentElement.textContent.trimEnd());
async function copy({currentTarget: target}) {
await navigator.clipboard.writeText(target.nextElementSibling.textContent.trim());
const [animation] = target.getAnimations({subtree: true});
if (animation) animation.currentTime = 0;
target.classList.add("observablehq-pre-copied");
target.addEventListener("animationend", () => target.classList.remove("observablehq-pre-copied"), {once: true});
}
8 changes: 4 additions & 4 deletions src/client/stdlib/fileAttachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ async function dsv(file, delimiter, {array = false, typed = false} = {}) {
}

export class AbstractFile {
constructor(name, mimeType) {
Object.defineProperty(this, "name", {value: name, enumerable: true});
if (mimeType !== undefined) Object.defineProperty(this, "mimeType", {value: mimeType + "", enumerable: true});
constructor(name, mimeType = "application/octet-stream") {
Object.defineProperty(this, "name", {value: `${name}`, enumerable: true});
Object.defineProperty(this, "mimeType", {value: `${mimeType}`, enumerable: true});
}
async blob() {
return (await remote_fetch(this)).blob();
Expand Down Expand Up @@ -100,7 +100,7 @@ class FileAttachmentImpl extends AbstractFile {
Object.defineProperty(this, "_url", {value: url});
}
async url() {
return (await this._url) + "";
return `${await this._url}`;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ export async function convert(
if (await maybeFetch(path, force, effects)) {
start = Date.now();
s = clack.spinner();
s.start(`Downloading ${bold(file.name)}`);
s.start(`Downloading ${bold(path)}`);
const response = await fetch(file.download_url);
if (!response.ok) throw new Error(`error fetching ${file.download_url}: ${response.status}`);
const buffer = Buffer.from(await response.arrayBuffer());
s.stop(`Downloaded ${bold(file.name)} ${faint(`in ${(Date.now() - start).toLocaleString("en-US")}ms`)}`);
s.stop(`Downloaded ${bold(path)} ${faint(`in ${(Date.now() - start).toLocaleString("en-US")}ms`)}`);
await effects.prepareOutput(path);
await effects.writeFile(path, buffer);
await effects.touch(path, file.create_time);
Expand Down
6 changes: 3 additions & 3 deletions src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ function handleWatch(socket: WebSocket, req: IncomingMessage, {root, style}: Con

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

type FileDeclaration = {name: string; mimeType: string | null; path: string};
type FileDeclaration = {name: string; mimeType?: string; path: string};
type FilePatch = {removed: string[]; added: FileDeclaration[]};

function diffFiles(oldFiles: Map<string, string>, newFiles: Map<string, string>): FilePatch {
Expand All @@ -463,7 +463,7 @@ function diffFiles(oldFiles: Map<string, string>, newFiles: Map<string, string>)
}
for (const [name, path] of newFiles) {
if (oldFiles.get(name) !== path) {
patch.added.push({name, mimeType: mime.getType(name), path});
patch.added.push({name, mimeType: mime.getType(name) ?? undefined, path});
}
}
return patch;
Expand Down
2 changes: 1 addition & 1 deletion src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function renderFiles(files: Iterable<string>, resolve: (name: string) => string)
function renderFile(name: string, resolve: (name: string) => string): string {
return `\nregisterFile(${JSON.stringify(name)}, ${JSON.stringify({
name,
mimeType: mime.getType(name),
mimeType: mime.getType(name) ?? undefined,
path: resolve(name)
})});`;
}
Expand Down
1 change: 1 addition & 0 deletions src/style/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ h6 {
margin-top: 0;
margin-bottom: 0.25rem;
scroll-margin-top: 1rem;
text-wrap: balance;
}

h2 + p,
Expand Down
29 changes: 29 additions & 0 deletions src/style/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,35 @@
align-items: center;
}

.observablehq-pre-copied::before {
content: "Copied!";
position: absolute;
right: calc(100% + 0.25rem);
background: var(--theme-background-alt);
color: var(--theme-green);
font: var(--font-small);
border-radius: 4px;
padding: 4px 8px;
pointer-events: none;
animation-name: observablehq-pre-copied;
animation-duration: 250ms;
animation-direction: alternate;
animation-iteration-count: 2;
}

@keyframes observablehq-pre-copied {
0% {
opacity: 0;
transform: translateX(0.5rem);
}
50% {
opacity: 1;
}
100% {
transform: translateX(0);
}
}

.observablehq-pre-container[data-copy] .observablehq-pre-copy,
.observablehq-pre-container:hover .observablehq-pre-copy,
.observablehq-pre-container .observablehq-pre-copy:focus {
Expand Down
Loading

0 comments on commit eb680d9

Please sign in to comment.