@knolljo/astro-sveltia-cms 0.0.1
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.
- package/README.md +51 -0
- package/dist/admin.astro +24 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +42 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# astro-sveltia-cms
|
|
2
|
+
|
|
3
|
+
Sveltia CMS integration for Astro.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install astro-sveltia-cms @sveltia/cms
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
In your `astro.config.mjs`:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { defineConfig } from "astro/config";
|
|
17
|
+
import sveltia from "astro-sveltia-cms";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
integrations: [
|
|
21
|
+
sveltia({
|
|
22
|
+
adminRoute: "/cms", // Optional, defaults to "/admin"
|
|
23
|
+
config: {
|
|
24
|
+
load_config_file: false,
|
|
25
|
+
backend: {
|
|
26
|
+
name: "github",
|
|
27
|
+
repo: "my/repo",
|
|
28
|
+
branch: "main",
|
|
29
|
+
},
|
|
30
|
+
media_folder: "public/images",
|
|
31
|
+
collections: [
|
|
32
|
+
// ... your collections
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
This will serve the Sveltia CMS admin interface at `/cms` (or `/admin` by default).
|
|
41
|
+
The configuration object is passed directly to `CMS.init()`.
|
|
42
|
+
|
|
43
|
+
## TypeScript
|
|
44
|
+
|
|
45
|
+
You can import `CmsConfig` from `@sveltia/cms` to type your configuration (if supported by your version of Sveltia CMS).
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import type { CmsConfig } from "@sveltia/cms";
|
|
49
|
+
|
|
50
|
+
const config: CmsConfig = { ... };
|
|
51
|
+
```
|
package/dist/admin.astro
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
export const prerender = true;
|
|
4
|
+
---
|
|
5
|
+
<!DOCTYPE html>
|
|
6
|
+
<html lang="en">
|
|
7
|
+
<head>
|
|
8
|
+
<meta charset="utf-8" />
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
10
|
+
<meta name="robots" content="noindex" />
|
|
11
|
+
<title>Content Management</title>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<script>
|
|
15
|
+
import { init } from "@sveltia/cms";
|
|
16
|
+
import { config, title } from "virtual:astro-sveltia-cms/config";
|
|
17
|
+
|
|
18
|
+
if (title) {
|
|
19
|
+
document.title = title;
|
|
20
|
+
}
|
|
21
|
+
init({ config });
|
|
22
|
+
</script>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AstroIntegration } from "astro";
|
|
2
|
+
export type CmsConfig = Record<string, any>;
|
|
3
|
+
export type SveltiaOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* The route where the CMS will be served.
|
|
6
|
+
* @default "/admin"
|
|
7
|
+
*/
|
|
8
|
+
adminRoute?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The page title for the CMS admin interface.
|
|
11
|
+
* @default "Content Management"
|
|
12
|
+
*/
|
|
13
|
+
adminTitle?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The Sveltia CMS configuration object.
|
|
16
|
+
*/
|
|
17
|
+
config: CmsConfig;
|
|
18
|
+
};
|
|
19
|
+
export default function sveltiaCms(options: SveltiaOptions): AstroIntegration;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export default function sveltiaCms(options) {
|
|
2
|
+
const adminRoute = options.adminRoute || "/admin";
|
|
3
|
+
const adminTitle = options.adminTitle || "Content Management";
|
|
4
|
+
const virtualModuleId = "virtual:astro-sveltia-cms/config";
|
|
5
|
+
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
6
|
+
return {
|
|
7
|
+
name: "astro-sveltia-cms",
|
|
8
|
+
hooks: {
|
|
9
|
+
"astro:config:setup": ({ injectRoute, updateConfig, logger }) => {
|
|
10
|
+
// Inject the admin page route
|
|
11
|
+
injectRoute({
|
|
12
|
+
pattern: adminRoute,
|
|
13
|
+
entrypoint: new URL("./admin.astro", import.meta.url),
|
|
14
|
+
});
|
|
15
|
+
// Register the virtual module plugin
|
|
16
|
+
updateConfig({
|
|
17
|
+
vite: {
|
|
18
|
+
plugins: [
|
|
19
|
+
{
|
|
20
|
+
name: "vite-plugin-astro-sveltia-cms-config",
|
|
21
|
+
resolveId(id) {
|
|
22
|
+
if (id === virtualModuleId) {
|
|
23
|
+
return resolvedVirtualModuleId;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
load(id) {
|
|
27
|
+
if (id === resolvedVirtualModuleId) {
|
|
28
|
+
return `
|
|
29
|
+
export const config = ${JSON.stringify(options.config)};
|
|
30
|
+
export const title = ${JSON.stringify(adminTitle)};
|
|
31
|
+
`;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
logger.info(`Sveltia CMS injected at ${adminRoute}`);
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@knolljo/astro-sveltia-cms",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Sveltia CMS integration for Astro",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"astro-integration"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.js",
|
|
11
|
+
"./admin.astro": "./dist/admin.astro"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc && cp src/admin.astro dist/admin.astro",
|
|
18
|
+
"dev": "tsc --watch"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@sveltia/cms": "^0.140.4",
|
|
22
|
+
"astro": "^4.0.0 || ^5.0.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@sveltia/cms": "^0.140.4",
|
|
26
|
+
"@types/node": "^20.0.0",
|
|
27
|
+
"astro": "^5.0.0",
|
|
28
|
+
"typescript": "^5.0.0"
|
|
29
|
+
}
|
|
30
|
+
}
|