-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 159cc99
Showing
39 changed files
with
14,630 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
.DS_Store | ||
dist | ||
tmp | ||
|
||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20.18.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"endOfLine": "auto", | ||
"jsxSingleQuote": false, | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 David Enke | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Astro Decap Collection | ||
|
||
Derive Astro collection schemata from Decap configs. | ||
|
||
## Local development | ||
|
||
Run a local tsx compiler in watch mode | ||
|
||
```bash | ||
npx tsx watch ./src/cli.ts -c ../website/public/admin/config.yml -t ../website/src/content | ||
``` | ||
|
||
## Validation only (runtime) | ||
|
||
This wont get you types, but you can still validate content against the schema. | ||
|
||
```typescript | ||
import { | ||
getCollection, | ||
loadDecapConfig, | ||
prepareSchema, | ||
transformCollection, | ||
} from 'astro-decap-collection'; | ||
import { defineCollection, z as zod } from 'astro:content'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
// load Decap config and transform it at runtime | ||
const configURL = fileURLToPath(new URL('../../public/admin/config.yml', import.meta.url)); | ||
const config = await loadDecapConfig(configURL); | ||
const collection = getCollection(config, 'blog')!; | ||
const schema = await transformCollection(collection, { zod }); | ||
|
||
export const collections = { | ||
blog: defineCollection(prepareSchema(schema.runtime)), | ||
}; | ||
``` | ||
|
||
## Types and validation (preferred) | ||
|
||
Transform the Decap config at build time and use the generated Zod schema. | ||
|
||
```bash | ||
# astrodecap-collection, adc - Binary name | ||
# --config, -c - Decap YML config file path to read from | ||
# --target, -t - Astro content directory path to write to | ||
adc -c ./public/admin/config.yml -t ./src/content | ||
``` | ||
|
||
```typescript | ||
import { defineCollection } from 'astro:content'; | ||
import { prepareSchema } from 'astro-decap-collection'; // wraps schema and adds content type | ||
|
||
import { schema as blogSchema } from './config.blog.ts'; // <-- generated from Decap before | ||
import { schema as pageSchema } from './config.pages.ts'; // <-- generated from Decap before | ||
|
||
export const collections = { | ||
blog: defineCollection(prepareSchema(blogSchema)), | ||
pages: defineCollection(prepareSchema(pageSchema)), | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createJsWithTsEsmPreset, type JestConfigWithTsJest } from 'ts-jest'; | ||
|
||
const esmPreset = createJsWithTsEsmPreset({ tsconfig: 'tsconfig.build.json' }); | ||
const jestConfig: JestConfigWithTsJest = { | ||
...esmPreset, | ||
extensionsToTreatAsEsm: ['.ts'], | ||
moduleFileExtensions: ['ts', 'js', 'json', 'node'], | ||
moduleNameMapper: { '(.+)\\.js': '$1' }, | ||
setupFiles: ['<rootDir>/jest.setup.ts'], | ||
transform: { | ||
'\\.[jt]s?$': ['ts-jest', { useESM: true }], | ||
}, | ||
}; | ||
|
||
export default jestConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { transpileModule, type TranspileOptions } from 'typescript'; | ||
import z from 'zod'; | ||
|
||
import tsConfig from './tsconfig.json'; | ||
|
||
declare global { | ||
function serializeShape(type: z.ZodType<any, any, any>): string; | ||
function transpileFrom(source: string): string; | ||
} | ||
|
||
globalThis.serializeShape = global.serializeShape = function (type) { | ||
const wrapped = z.strictObject({ type }); | ||
return JSON.stringify(wrapped.shape); | ||
}; | ||
|
||
globalThis.transpileFrom = global.transpileFrom = function (source) { | ||
const { outputText } = transpileModule(source, tsConfig as unknown as TranspileOptions); | ||
return outputText; | ||
}; | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
locale: "de" | ||
|
||
backend: | ||
name: git-gateway | ||
branch: main | ||
|
||
publish_mode: editorial_workflow | ||
|
||
media_folder: "/public/media" | ||
public_folder: "/public/media" | ||
|
||
collections: | ||
- name: "blog" # Used in routes, e.g., /admin/collections/blog | ||
label: "Blog" # Used in the UI | ||
folder: "packages/website/src/content/blog" # The path to the folder where the documents are stored | ||
create: true # Allow users to create new documents in this collection | ||
fields: # The fields for each document, usually in frontmatter | ||
- { label: "Layout", name: "layout", widget: "hidden", default: "blog" } | ||
- { label: "Title", name: "title", widget: "string" } | ||
- { label: "Published", name: "published", widget: "boolean" } | ||
- { label: "Color", name: "color", widget: "color", enableAlpha: true } | ||
- { label: "Place", name: "place", widget: "map", hint: "Set a location" } | ||
- { label: "Publish Date", name: "date", widget: "datetime" } | ||
- { label: "Featured Image(s)", name: "thumbnail", widget: "image" } | ||
- { label: "Rating", name: "rating", widget: "number", min: 1, max: 5 } | ||
- { label: "Code", name: "code", widget: "code", output_code_only: true } | ||
- { label: "Body", name: "body", widget: "markdown" } |
Oops, something went wrong.