Skip to content

Commit f514459

Browse files
author
Will Scullin
authored
Strip more locations from models (#240)
1 parent 234489e commit f514459

10 files changed

Lines changed: 64 additions & 25 deletions

File tree

package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"fs-extra": "^10.1.0",
4343
"http-server": "^14.1.1",
4444
"jsdom": "^19.0.0",
45+
"prettier": "^3.0.1",
4546
"remark-gfm": "^1.0.0",
4647
"remark-parse": "^10.0.1",
4748
"shiki": "^0.10.1",

scripts/context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
import packageJson from "../package.json";
2424
const argIndex = process.argv.indexOf("--baseurl");
25-
const BASEURL = argIndex != -1 ? process.argv[argIndex + 1] : undefined;
25+
const BASEURL = argIndex != -1 ? process.argv[argIndex + 1] : undefined;
2626

2727
if (BASEURL === undefined) {
2828
throw new Error("--baseurl is required");
@@ -31,7 +31,7 @@ if (BASEURL === undefined) {
3131
export const DEFAULT_CONTEXT = {
3232
site: {
3333
baseurl: BASEURL,
34-
ga_site_id: 'G-0M10W7C20Y',
34+
ga_site_id: "G-0M10W7C20Y",
3535
malloyRenderVersion: packageJson.devDependencies["@malloydata/render"],
3636
},
37-
}
37+
};

scripts/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ export interface DocsError {
2727
position: Position;
2828
message: string;
2929
path: string;
30-
}
30+
}

scripts/highlighter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ const malloySQLTMGrammar = JSON.parse(
6363
const HIGHLIGHTER = shiki.getHighlighter({
6464
theme: "light-plus",
6565
paths: {
66-
themes: "node_modules/shiki/themes/",
67-
languages: "node_modules/shiki/languages/"
66+
themes: "node_modules/shiki/themes/",
67+
languages: "node_modules/shiki/languages/",
6868
},
6969
langs: [
7070
"sql",

scripts/log.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ const YELLOW = "\x1b[33m";
2626
const GREEN = "\x1b[32m";
2727
const RESET = "\x1b[0m";
2828

29-
export function log(message: string, style: "error" | "info" | "warning" | "success" = "info"): void {
29+
export function log(
30+
message: string,
31+
style: "error" | "info" | "warning" | "success" = "info"
32+
): void {
3033
const color = {
3134
error: RED,
3235
info: "",

scripts/markdown_types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export type Markdown =
4848
| Yaml;
4949

5050
export interface Position {
51-
start: { line: number, column: number, offset: number },
52-
end: { line: number, column: number, offset: number }
53-
};
51+
start: { line: number; column: number; offset: number };
52+
end: { line: number; column: number; offset: number };
53+
}
5454

5555
export interface Node {
5656
position: Position;

scripts/page.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ function enrichTableOfContents(sections: Section[]): EnrichedSection[] {
6363
const fullLink = path.join("/documentation", item.link);
6464
const compareLink = convertDocPathToHTML(fullLink);
6565
const htmlLinkRaw = fullLink.replace(/\.malloynb$/, "");
66-
const htmlLink = htmlLinkRaw === "/documentation/index" ? "/documentation" : htmlLinkRaw;
66+
const htmlLink =
67+
htmlLinkRaw === "/documentation/index"
68+
? "/documentation"
69+
: htmlLinkRaw;
6770
return { title: item.title, link: item.link, htmlLink, compareLink };
6871
} else {
6972
return enrichTableOfContents([item])[0];
@@ -141,15 +144,16 @@ const FOOTER_TEMPLATE_STRING = `
141144
<a href="{{ next.relative }}">{{ next.title }}<img src="{{ site.baseurl }}/img/next.svg" alt="next"/></a>
142145
{{/if }}
143146
</div>
144-
</div>`
147+
</div>`;
145148
const FOOTER_TEMPLATE = Handlebars.compile(FOOTER_TEMPLATE_STRING);
146149

147150
export function renderFooter(
148151
sections: Section[],
149152
rootPath: string,
150153
docPath: string
151154
): string {
152-
const makeFullLink = (l: string) => path.join('/documentation', convertDocPathToHTML(l));
155+
const makeFullLink = (l: string) =>
156+
path.join("/documentation", convertDocPathToHTML(l));
153157
const items = extractItems(sections);
154158
const thisIndex = items.findIndex(
155159
(item) => makeFullLink(item.link) === docPath
@@ -175,13 +179,17 @@ export function renderFooter(
175179

176180
return FOOTER_TEMPLATE({
177181
...DEFAULT_CONTEXT,
178-
next: next ? {
179-
relative: nextRelative,
180-
title: next.title
181-
} : undefined,
182-
previous: previous ? {
183-
relative: previousRelative,
184-
title: previous.title
185-
} : undefined,
182+
next: next
183+
? {
184+
relative: nextRelative,
185+
title: next.title,
186+
}
187+
: undefined,
188+
previous: previous
189+
? {
190+
relative: previousRelative,
191+
title: previous.title,
192+
}
193+
: undefined,
186194
});
187195
}

scripts/run_code.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ const isLocation = (value: unknown) => {
253253

254254
const stripLocation = (modelDef: ModelDef): ModelDef => {
255255
return JSON.parse(JSON.stringify(modelDef), (key, value) => {
256-
if (key === "location" && isLocation(value)) {
256+
if (["location", "at"].includes(key) && isLocation(value)) {
257257
return undefined;
258258
} else {
259259
return value;

scripts/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ import fs from "fs";
2525
import path from "path";
2626

2727
export function isMalloyNB(file: string): boolean {
28-
return file.endsWith(".malloysql") || file.endsWith(".malloynb") || file.endsWith("quick_reference.html");
28+
return (
29+
file.endsWith(".malloysql") ||
30+
file.endsWith(".malloynb") ||
31+
file.endsWith("quick_reference.html")
32+
);
2933
}
3034

3135
export function convertDocPathToHTML(file: string): string {
@@ -82,7 +86,7 @@ export function escape(html: string): string {
8286
">": "&gt;",
8387
'"': "&quot;",
8488
"'": "&#39;",
85-
}[ch] || "")
89+
})[ch] || ""
8690
);
8791
}
8892

@@ -124,5 +128,5 @@ export function watchDebouncedRecursive(
124128
}
125129

126130
export function hashForHeading(heading: string) {
127-
return heading.toLowerCase().replace(/[^\w]+/g, "-");;
131+
return heading.toLowerCase().replace(/[^\w]+/g, "-");
128132
}

0 commit comments

Comments
 (0)