Skip to content

Commit d658d32

Browse files
committed
ci: fix sync-docs workflow
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 2dca030 commit d658d32

1 file changed

Lines changed: 66 additions & 3 deletions

File tree

.github/actions/prepare-docs/lib/utils/asset-registry.js

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function resolveAssetPublicPath({
3838

3939
const normalizedTarget = normalizeAssetLinkTarget(
4040
docRelativePath,
41-
targetPath,
41+
targetPath
4242
);
4343
if (!normalizedTarget) {
4444
return null;
@@ -49,6 +49,15 @@ function resolveAssetPublicPath({
4949
return null;
5050
}
5151

52+
const namespacedAssetPath = deriveStaticPublicPath({
53+
staticPath,
54+
storageRelativePath: registration.storageRelativePath,
55+
});
56+
57+
if (namespacedAssetPath) {
58+
return namespacedAssetPath;
59+
}
60+
5261
const relativePath = deriveRelativeAssetPath({
5362
docRelativePath,
5463
docsPath,
@@ -63,6 +72,60 @@ function resolveAssetPublicPath({
6372
return registration.publicPath || null;
6473
}
6574

75+
function deriveStaticPublicPath({ staticPath, storageRelativePath }) {
76+
if (!staticPath || !storageRelativePath) {
77+
return null;
78+
}
79+
80+
const normalizedStaticRoot = normalizeToPosix(staticPath);
81+
const normalizedStorage = normalizeToPosix(storageRelativePath);
82+
83+
if (!normalizedStaticRoot || !normalizedStorage) {
84+
return null;
85+
}
86+
87+
const namespace = extractStaticNamespace(normalizedStaticRoot);
88+
89+
const combinedPath = namespace
90+
? path.posix.join(namespace, normalizedStorage)
91+
: normalizedStorage;
92+
93+
if (!combinedPath) {
94+
return null;
95+
}
96+
97+
return `/${combinedPath}`.replace(/\/+/g, "/");
98+
}
99+
100+
function extractStaticNamespace(staticRoot) {
101+
if (!staticRoot) {
102+
return null;
103+
}
104+
105+
const segments = staticRoot.split("/").filter(Boolean);
106+
if (!segments.length) {
107+
return "";
108+
}
109+
110+
const staticIndex = segments.lastIndexOf("static");
111+
if (staticIndex === -1) {
112+
return path.posix.basename(staticRoot);
113+
}
114+
115+
const namespaceSegments = segments.slice(staticIndex + 1).filter(Boolean);
116+
if (!namespaceSegments.length) {
117+
return "";
118+
}
119+
120+
const namespace = namespaceSegments.join("/");
121+
122+
if (namespace.startsWith("..")) {
123+
return "";
124+
}
125+
126+
return namespace;
127+
}
128+
66129
function deriveRelativeAssetPath({
67130
docRelativePath,
68131
docsPath,
@@ -96,12 +159,12 @@ function deriveRelativeAssetPath({
96159

97160
const assetFullPath = path.posix.join(
98161
normalizedStaticRoot,
99-
normalizeToPosix(storageRelativePath),
162+
normalizeToPosix(storageRelativePath)
100163
);
101164

102165
const relativePath = path.posix.relative(
103166
effectiveDocDirectory,
104-
assetFullPath,
167+
assetFullPath
105168
);
106169

107170
if (!relativePath) {

0 commit comments

Comments
 (0)