Skip to content

Commit f59f3cf

Browse files
committed
project title
1 parent 38662dd commit f59f3cf

File tree

6 files changed

+17
-10
lines changed

6 files changed

+17
-10
lines changed

docs/.observablehq/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
title: "Observable CLI",
23
pages: [
34
{path: "/index", name: "Overview"},
45
{path: "/getting-started", name: "Getting started"},

docs/index.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
---
2-
title: Overview
3-
---
4-
51
# Observable CLI
62

73
```js

src/build.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {basename, dirname, join, normalize, relative} from "node:path";
44
import {cwd} from "node:process";
55
import {fileURLToPath} from "node:url";
66
import {parseArgs} from "node:util";
7+
import {readConfig} from "./config.js";
78
import {Loader} from "./dataloader.js";
89
import {prepareOutput, visitFiles, visitMarkdownFiles} from "./files.js";
910
import {readPages} from "./navigation.js";
@@ -28,6 +29,7 @@ export async function build(context: CommandContext = makeCommandContext()) {
2829
}
2930

3031
// Render .md files, building a list of file attachments as we go.
32+
const config = await readConfig(sourceRoot);
3133
const pages = await readPages(sourceRoot);
3234
const files: string[] = [];
3335
const resolver = await makeCLIResolver();
@@ -40,6 +42,7 @@ export async function build(context: CommandContext = makeCommandContext()) {
4042
root: sourceRoot,
4143
path,
4244
pages,
45+
title: config?.title,
4346
resolver
4447
});
4548
files.push(...render.files.map((f) => join(dirname(sourceFile), f.name)));

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {stat} from "node:fs/promises";
22
import {join} from "node:path";
3-
import {type RenderOptions} from "./render.js";
43

54
export interface Config {
6-
pages?: RenderOptions["pages"];
5+
title?: string;
6+
pages?: {path: string; name: string}[];
77
}
88

99
export async function readConfig(root: string): Promise<Config | undefined> {

src/preview.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {fileURLToPath} from "node:url";
66
import {parseArgs} from "node:util";
77
import send from "send";
88
import {type WebSocket, WebSocketServer} from "ws";
9+
import {readConfig} from "./config.js";
910
import {Loader} from "./dataloader.js";
1011
import {HttpError, isHttpError, isNodeError} from "./error.js";
1112
import {maybeStat} from "./files.js";
@@ -118,6 +119,7 @@ class Server {
118119
root: this.root,
119120
path: pathname,
120121
pages,
122+
title: (await readConfig(this.root))?.title,
121123
resolver: this._resolver!
122124
})
123125
).html

src/render.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {dirname, join} from "node:path";
2+
import {type Config} from "./config.js";
23
import {computeHash} from "./hash.js";
34
import {resolveImport} from "./javascript/imports.js";
45
import {type FileReference, type ImportReference} from "./javascript.js";
@@ -10,10 +11,9 @@ export interface Render {
1011
imports: ImportReference[];
1112
}
1213

13-
export interface RenderOptions {
14+
export interface RenderOptions extends Config {
1415
root: string;
1516
path: string;
16-
pages?: {path: string; name: string}[];
1717
resolver: (cell: CellPiece) => CellPiece;
1818
}
1919

@@ -49,14 +49,19 @@ type RenderInternalOptions =
4949

5050
function render(
5151
parseResult: ParseResult,
52-
{path, pages, preview, hash, resolver}: RenderOptions & RenderInternalOptions
52+
{path, pages, title, preview, hash, resolver}: RenderOptions & RenderInternalOptions
5353
): string {
5454
const showSidebar = pages && pages.length > 1;
5555
return `<!DOCTYPE html>
5656
<meta charset="utf-8">
5757
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
5858
${
59-
parseResult.title ? `<title>${escapeData(parseResult.title)}</title>\n` : ""
59+
parseResult.title || title
60+
? `<title>${[parseResult.title, parseResult.title === title ? null : title]
61+
.filter((title): title is string => !!title)
62+
.map((title) => escapeData(title))
63+
.join(" | ")}</title>\n`
64+
: ""
6065
}<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
6166
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Source+Serif+Pro:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap">
6267
<link rel="stylesheet" type="text/css" href="/_observablehq/style.css">

0 commit comments

Comments
 (0)