Skip to content

Commit 820c6ac

Browse files
committed
Use joinUrlPath consistently
1 parent 815a611 commit 820c6ac

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

convert/convertBooks.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import { freeze, postQueries, queries } from '../sab-proskomma-tools';
88
import { SABProskomma } from '../src/lib/sab-proskomma';
99
import type { ConfigTaskOutput } from './convertConfig';
1010
import { convertMarkdownsToMilestones } from './convertMarkdown';
11-
import { createHashedFile, createOutputDir, getHashedNameFromContents } from './fileUtils';
11+
import {
12+
createHashedFile,
13+
createOutputDir,
14+
getHashedNameFromContents,
15+
joinUrlPath
16+
} from './fileUtils';
1217
import { hasAudioExtension, hasImageExtension } from './stringUtils';
1318
import { Promisable, Task, TaskOutput } from './Task';
1419
import { verifyGlossaryEntries } from './verifyGlossaryEntries';
@@ -246,11 +251,11 @@ function updateImgTags(
246251
} else {
247252
const imagePath = createHashedFile(
248253
context.dataDir,
249-
`illustrations/${fileName}`,
254+
joinUrlPath('illustrations', fileName),
250255
context.verbose
251256
);
252257

253-
return match.replace(/src=["'][^"']*["']/, `src="${base}/${imagePath}"`);
258+
return match.replace(/src=["'][^"']*["']/, `src="${joinUrlPath(base, imagePath)}"`);
254259
}
255260
}
256261
);

convert/convertContents.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path';
33
import { ScriptureConfig } from '$config';
44
import jsdom from 'jsdom';
55
import { ConfigTaskOutput, parseLangAttribute } from './convertConfig';
6-
import { createHashedFile, createOutputDir, deleteOutputDir } from './fileUtils';
6+
import { createHashedFile, createOutputDir, deleteOutputDir, joinUrlPath } from './fileUtils';
77
import { Task, TaskOutput } from './Task';
88

99
type ContentItem = {
@@ -215,12 +215,12 @@ export function convertContents(
215215
scriptureConfig.bookCollections?.some((collection) => {
216216
if (verbose) console.log(`Searching for ${linkTarget} in ${collection.id}`);
217217
const book = collection.books.find((x) => x.id === linkTarget);
218-
if (book && book.type) {
218+
if (book && book.type && linkTarget) {
219219
// We found a book and the book.type is not default (i.e. undefined)
220220
if (verbose)
221221
console.log(`Found ${linkTarget} in ${collection.id} as ${book.type}`);
222222
linkType = book.type;
223-
linkLocation = `${linkType}/${collection.id}/${linkTarget}`;
223+
linkLocation = joinUrlPath(linkType, collection.id, linkTarget);
224224
return true;
225225
}
226226
});

convert/convertManifest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
22
import path from 'path';
3-
import { createHashedFile, createHashedFileFromContents } from './fileUtils';
3+
import { createHashedFile, createHashedFileFromContents, joinUrlPath } from './fileUtils';
44
import { Task, TaskOutput } from './Task';
55

66
export interface ManifestTaskOutput extends TaskOutput {
@@ -55,7 +55,7 @@ export function convertManifest(dataDir: string, verbose: number) {
5555
throw new Error(`Required icon file ${iconPath} does not exist!`);
5656
}
5757

58-
line = line.replace(srcMatch[0], `"src": "./${finalName}"`);
58+
line = line.replace(srcMatch[0], `"src": "${joinUrlPath('.', finalName)}"`);
5959
}
6060
return line;
6161
})

convert/convertStyles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { copyFileSync, existsSync, readdirSync, readFileSync, writeFileSync } from 'fs';
22
import path from 'path';
33
import { ConfigTaskOutput } from 'convertConfig';
4-
import { createOutputDir } from './fileUtils';
4+
import { createOutputDir, joinUrlPath } from './fileUtils';
55
import { compareVersions } from './stringUtils';
66
import { Task, TaskOutput } from './Task';
77

@@ -99,7 +99,7 @@ export function convertStyles(dataDir: string, configData: ConfigTaskOutput, ver
9999
);
100100
}
101101
}
102-
line = line.replace('/fonts', `$assets/${finalPath}`);
102+
line = line.replace('/fonts', joinUrlPath('$assets', finalPath));
103103
}
104104
return line;
105105
})

0 commit comments

Comments
 (0)