starlight-cannoli-plugins 2.1.6 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
rm,
|
|
13
13
|
stat
|
|
14
14
|
} from "fs/promises";
|
|
15
|
-
import { resolve, relative,
|
|
15
|
+
import { resolve, relative, dirname } from "path";
|
|
16
16
|
import { minimatch } from "minimatch";
|
|
17
17
|
var DEFAULT_SRC_DIR = "src/content/docs";
|
|
18
18
|
var DEFAULT_PUBLIC_DIR = "public";
|
|
@@ -48,18 +48,8 @@ async function fullSync(srcDir, publicDir, preserveDirs, ignorePatterns) {
|
|
|
48
48
|
function isMdFile(filePath) {
|
|
49
49
|
return filePath.endsWith(".md") || filePath.endsWith(".mdx");
|
|
50
50
|
}
|
|
51
|
-
function isIndexMd(filePath) {
|
|
52
|
-
const base = basename(filePath);
|
|
53
|
-
return base === "index.md" || base === "index.mdx";
|
|
54
|
-
}
|
|
55
51
|
function getDestPath(srcFilePath, srcDir, publicDir) {
|
|
56
|
-
|
|
57
|
-
if (!isMdFile(srcFilePath) || isIndexMd(srcFilePath)) {
|
|
58
|
-
return resolve(publicDir, rel);
|
|
59
|
-
}
|
|
60
|
-
const ext = extname(srcFilePath);
|
|
61
|
-
const stem = basename(srcFilePath, ext);
|
|
62
|
-
return resolve(publicDir, dirname(rel), stem, `index${ext}`);
|
|
52
|
+
return resolve(publicDir, relative(srcDir, srcFilePath));
|
|
63
53
|
}
|
|
64
54
|
async function copyMdFile(srcFilePath, srcDir, publicDir) {
|
|
65
55
|
const destPath = getDestPath(srcFilePath, srcDir, publicDir);
|
|
@@ -144,10 +134,11 @@ function syncDocsToPublic(options) {
|
|
|
144
134
|
const srcDir = resolve(DEFAULT_SRC_DIR);
|
|
145
135
|
const publicDir = resolve(DEFAULT_PUBLIC_DIR);
|
|
146
136
|
const {
|
|
147
|
-
preserveDirs,
|
|
137
|
+
preserveDirs: rawPreserveDirs,
|
|
148
138
|
ignorePatterns = [],
|
|
149
139
|
exposePageSrcButton = false
|
|
150
140
|
} = options;
|
|
141
|
+
const preserveDirs = rawPreserveDirs.map((d) => d.replace(/\/+$/, ""));
|
|
151
142
|
return {
|
|
152
143
|
name: "astro-sync-docs-to-public",
|
|
153
144
|
hooks: {
|
|
@@ -155,15 +146,21 @@ function syncDocsToPublic(options) {
|
|
|
155
146
|
validateOptions(options);
|
|
156
147
|
if (exposePageSrcButton) {
|
|
157
148
|
const currentFile = fileURLToPath(import.meta.url);
|
|
158
|
-
|
|
159
|
-
|
|
149
|
+
let pageScriptUrl;
|
|
150
|
+
if (currentFile.endsWith(".ts")) {
|
|
151
|
+
pageScriptUrl = new URL("./page-script.ts", import.meta.url);
|
|
152
|
+
} else if (currentFile.endsWith("astro-sync-docs-to-public.js")) {
|
|
153
|
+
pageScriptUrl = new URL(
|
|
160
154
|
"./astro-sync-docs-to-public/page-script.js",
|
|
161
155
|
import.meta.url
|
|
162
|
-
)
|
|
156
|
+
);
|
|
157
|
+
} else {
|
|
158
|
+
pageScriptUrl = new URL(
|
|
163
159
|
"./plugins/astro-sync-docs-to-public/page-script.js",
|
|
164
160
|
import.meta.url
|
|
165
|
-
)
|
|
166
|
-
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
const scriptPath = fileURLToPath(pageScriptUrl);
|
|
167
164
|
injectScript("page", `import ${JSON.stringify(scriptPath)};`);
|
|
168
165
|
}
|
|
169
166
|
},
|
|
@@ -213,9 +210,7 @@ function syncDocsToPublic(options) {
|
|
|
213
210
|
}
|
|
214
211
|
};
|
|
215
212
|
}
|
|
216
|
-
var starlightSyncDocsToPublic = syncDocsToPublic;
|
|
217
213
|
|
|
218
214
|
export {
|
|
219
|
-
syncDocsToPublic
|
|
220
|
-
starlightSyncDocsToPublic
|
|
215
|
+
syncDocsToPublic
|
|
221
216
|
};
|
package/dist/index.js
CHANGED
|
@@ -16,10 +16,17 @@ function showSuccessBanner(message) {
|
|
|
16
16
|
}
|
|
17
17
|
async function getRawMdUrl() {
|
|
18
18
|
const base = window.location.href.replace(/\/?$/, "/");
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
for (const ext of [".md", ".mdx"]) {
|
|
20
|
+
const url = new URL(`index${ext}`, base).toString();
|
|
21
|
+
if ((await fetch(url, { method: "HEAD" })).ok) return url;
|
|
22
|
+
}
|
|
23
|
+
const segment = new URL(base).pathname.replace(/\/$/, "").split("/").pop();
|
|
24
|
+
const parentBase = new URL("../", base).toString();
|
|
25
|
+
for (const ext of [".md", ".mdx"]) {
|
|
26
|
+
const url = new URL(`${segment}${ext}`, parentBase).toString();
|
|
27
|
+
if ((await fetch(url, { method: "HEAD" })).ok) return url;
|
|
28
|
+
}
|
|
29
|
+
return new URL("index.md", base).toString();
|
|
23
30
|
}
|
|
24
31
|
function createActionBar() {
|
|
25
32
|
const bar = document.createElement("div");
|
|
@@ -19,7 +19,5 @@ interface SyncDocsToPublicOptions {
|
|
|
19
19
|
exposePageSrcButton?: boolean;
|
|
20
20
|
}
|
|
21
21
|
declare function syncDocsToPublic(options: SyncDocsToPublicOptions): AstroIntegration;
|
|
22
|
-
/** @deprecated Use {@link syncDocsToPublic} instead. */
|
|
23
|
-
declare const starlightSyncDocsToPublic: typeof syncDocsToPublic;
|
|
24
22
|
|
|
25
|
-
export { type SyncDocsToPublicOptions,
|
|
23
|
+
export { type SyncDocsToPublicOptions, syncDocsToPublic };
|
package/package.json
CHANGED