Skip to content

Commit 2a18cf8

Browse files
committed
Embed absolute manifest URLs and detect repo slug
Update project README generation to embed the full manifest URL instead of a placeholder/relative path. generate.js: generateProjectReadme now accepts a manifestUrl and generateProject() builds manifestUrl from siteBaseUrl and projectName before writing the README. projects/example-project/README.md links updated to use the absolute manifest URL. utils.js: enhance getRepoSlugFromEnv to fall back to reading the git remote origin URL (supports HTTPS and SSH formats) when GITHUB_REPOSITORY is not set; adds execSync import and returns an empty string on failure. These changes allow local runs to produce READMEs with correct viewer links and derive repo info outside CI.
1 parent d194bb1 commit 2a18cf8

3 files changed

Lines changed: 33 additions & 7 deletions

File tree

projects/example-project/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ This project is generated by repository scripts.
1212
- WARNING.md
1313

1414
## Links
15-
- Manifest: ./manifest.json
15+
- Manifest: https://example.org/projects/example-project/manifest.json
1616
- Images folder: ./images/
17-
- Mirador (replace MANIFEST_URL): https://projectmirador.org/embed/?iiif-content=MANIFEST_URL
18-
- Universal Viewer (replace MANIFEST_URL): https://uv-v3.netlify.app/#?manifest=MANIFEST_URL
17+
- Mirador: https://projectmirador.org/embed/?iiif-content=https://example.org/projects/example-project/manifest.json
18+
- Universal Viewer: https://uv-v3.netlify.app/#?manifest=https://example.org/projects/example-project/manifest.json
1919

2020
## TPEN3
2121
Use the generated manifest URL in TPEN3 when creating a new transcription project.

scripts/generate.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,8 @@ function buildManifest({ projectName, siteBaseUrl, info, resources, warnings })
668668
return manifest
669669
}
670670

671-
function generateProjectReadme(projectName) {
672-
return `# ${projectName}\n\nThis project is generated by repository scripts.\n\n## Inputs\n- Add local images in images/\n- Add external references using .lnk files in images/ (one HTTP(S) URL per file)\n- Optional advanced configuration in info.yml\n\n## Generated Outputs\n- manifest.json\n- WARNING.md\n\n## Links\n- Manifest: ./manifest.json\n- Images folder: ./images/\n- Mirador (replace MANIFEST_URL): https://projectmirador.org/embed/?iiif-content=MANIFEST_URL\n- Universal Viewer (replace MANIFEST_URL): https://uv-v3.netlify.app/#?manifest=MANIFEST_URL\n\n## TPEN3\nUse the generated manifest URL in TPEN3 when creating a new transcription project.\n\n> This file is regenerated when manifest generation runs. Put durable custom metadata in info.yml.\n`
671+
function generateProjectReadme(projectName, manifestUrl) {
672+
return `# ${projectName}\n\nThis project is generated by repository scripts.\n\n## Inputs\n- Add local images in images/\n- Add external references using .lnk files in images/ (one HTTP(S) URL per file)\n- Optional advanced configuration in info.yml\n\n## Generated Outputs\n- manifest.json\n- WARNING.md\n\n## Links\n- Manifest: ${manifestUrl}\n- Images folder: ./images/\n- Mirador: https://projectmirador.org/embed/?iiif-content=${manifestUrl}\n- Universal Viewer: https://uv-v3.netlify.app/#?manifest=${manifestUrl}\n\n## TPEN3\nUse the generated manifest URL in TPEN3 when creating a new transcription project.\n\n> This file is regenerated when manifest generation runs. Put durable custom metadata in info.yml.\n`
673673
}
674674

675675
function generateWarningsMarkdown(projectName, warnings) {
@@ -725,10 +725,11 @@ async function generateProject(projectName) {
725725
resources: orderedResources,
726726
warnings
727727
})
728+
const manifestUrl = `${siteBaseUrl}/projects/${projectName}/manifest.json`
728729

729730
await ensureDir(projectDir)
730731
await writeJson(manifestPath, manifest)
731-
await writeText(readmePath, generateProjectReadme(projectName))
732+
await writeText(readmePath, generateProjectReadme(projectName, manifestUrl))
732733
await writeText(warningPath, generateWarningsMarkdown(projectName, warnings))
733734

734735
return {

scripts/utils.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from "node:fs/promises"
22
import path from "node:path"
3+
import { execSync } from "node:child_process"
34
import { fileURLToPath } from "node:url"
45
import yaml from "js-yaml"
56

@@ -119,7 +120,31 @@ export async function writeText(filePath, text) {
119120
}
120121

121122
export function getRepoSlugFromEnv() {
122-
return process.env.GITHUB_REPOSITORY ?? ""
123+
if (process.env.GITHUB_REPOSITORY) {
124+
return process.env.GITHUB_REPOSITORY
125+
}
126+
127+
try {
128+
const remoteUrl = execSync("git config --get remote.origin.url", {
129+
cwd: repoRoot,
130+
encoding: "utf8",
131+
stdio: ["ignore", "pipe", "ignore"]
132+
}).trim()
133+
134+
const httpsMatch = remoteUrl.match(/^https:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?$/i)
135+
if (httpsMatch) {
136+
return `${httpsMatch[1]}/${httpsMatch[2]}`
137+
}
138+
139+
const sshMatch = remoteUrl.match(/^git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?$/i)
140+
if (sshMatch) {
141+
return `${sshMatch[1]}/${sshMatch[2]}`
142+
}
143+
} catch {
144+
return ""
145+
}
146+
147+
return ""
123148
}
124149

125150
export function buildSiteBaseUrl() {

0 commit comments

Comments
 (0)