Skip to content

Commit bf48448

Browse files
claude: Consolidate isExternalPath helper to src/core/url.ts
Move the duplicated isExternalPath function to a single location in src/core/url.ts and update all call sites to import from there. This addresses feedback from @cderv on PR #13901. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3cd1e7f commit bf48448

5 files changed

Lines changed: 12 additions & 19 deletions

File tree

src/core/brand/brand.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { InternalError } from "../lib/error.ts";
3232
import { dirname, join, relative, resolve } from "../../deno_ral/path.ts";
3333
import { warnOnce } from "../log.ts";
3434
import { isCssColorName } from "../css/color-names.ts";
35+
import { isExternalPath } from "../url.ts";
3536
import {
3637
LogoLightDarkSpecifierPathOptional,
3738
LogoOptionsPathOptional,
@@ -272,10 +273,6 @@ export class Brand {
272273
}
273274
}
274275

275-
function isExternalPath(path: string) {
276-
return /^\w+:/.test(path);
277-
}
278-
279276
export type LightDarkBrand = {
280277
light?: Brand;
281278
dark?: Brand;

src/core/sass/brand.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { Brand } from "../brand/brand.ts";
2626
import { darkModeDefault } from "../../format/html/format-html-info.ts";
2727
import { kBrandMode } from "../../config/constants.ts";
2828
import { join, relative } from "../../deno_ral/path.ts";
29+
import { isExternalPath } from "../url.ts";
2930

3031
const defaultColorNameMap: Record<string, string> = {
3132
"link-color": "link",
@@ -150,8 +151,6 @@ const googleFontImportString = (description: BrandFontGoogle) => {
150151
}:${styleString}wght@${weights}&display=${display}');`;
151152
};
152153

153-
const isExternalPath = (path: string) => /^\w+:/.test(path);
154-
155154
const fileFontImportString = (brand: Brand, description: BrandFontFile) => {
156155
const pathPrefix = relative(brand.projectDir, brand.brandDir);
157156
const parts = [];

src/core/url.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
/*
2-
* url.ts
3-
*
4-
* Copyright (C) 2020-2022 Posit Software, PBC
5-
*
6-
*/
2+
* url.ts
3+
*
4+
* Copyright (C) 2020-2022 Posit Software, PBC
5+
*/
76

87
import { ensureTrailingSlash, pathWithForwardSlashes } from "./path.ts";
98

109
export function isHttpUrl(url: string) {
1110
return /^https?:/i.test(url);
1211
}
1312

13+
export function isExternalPath(path: string) {
14+
return /^\w+:/.test(path);
15+
}
16+
1417
export function joinUrl(baseUrl: string, path: string) {
1518
const baseHasSlash = baseUrl.endsWith("/");
1619

src/project/types/website/website-navigation.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Document, Element } from "../../../core/deno-dom.ts";
1212

1313
import { pathWithForwardSlashes, safeExistsSync } from "../../../core/path.ts";
1414
import { resourcePath } from "../../../core/resources.ts";
15+
import { isExternalPath } from "../../../core/url.ts";
1516
import { renderEjs } from "../../../core/ejs.ts";
1617
import { warnOnce } from "../../../core/log.ts";
1718
import { asHtmlId } from "../../../core/html.ts";
@@ -1540,10 +1541,6 @@ function navigationDependency(resource: string) {
15401541
};
15411542
}
15421543

1543-
function isExternalPath(path: string) {
1544-
return /^\w+:/.test(path);
1545-
}
1546-
15471544
function resolveNavReferences(
15481545
collection: unknown | Array<unknown> | Record<string, unknown>,
15491546
) {

src/project/types/website/website-utils.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Document, Element } from "../../../core/deno-dom.ts";
88
import { getDecodedAttribute } from "../../../core/html.ts";
99
import { resolveInputTarget } from "../../project-index.ts";
1010
import { pathWithForwardSlashes, safeExistsSync } from "../../../core/path.ts";
11+
import { isExternalPath } from "../../../core/url.ts";
1112
import { projectOffset, projectOutputDir } from "../../project-shared.ts";
1213
import { engineValidExtensions } from "../../../execute/engine.ts";
1314
import { ProjectContext } from "../../types.ts";
@@ -119,7 +120,3 @@ export async function resolveProjectInputLinks(
119120
}
120121
}
121122
}
122-
123-
function isExternalPath(path: string) {
124-
return /^\w+:/.test(path);
125-
}

0 commit comments

Comments
 (0)