Skip to content

Commit

Permalink
add notifications to cms
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostrider-05 committed Sep 29, 2024
1 parent 7e6021c commit 9d15646
Show file tree
Hide file tree
Showing 9 changed files with 424 additions and 248 deletions.
38 changes: 6 additions & 32 deletions docs/.vitepress/config/cms/blocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createField, DecapCmsField, fieldToSnakeCase, Options } from 'vite-plugin-decap-cms'

import * as fields from './fields/'

type Block = NonNullable<NonNullable<Options['script']>['markdownEditorComponents']>[number]

interface ComponentBlockOptions {
Expand Down Expand Up @@ -32,13 +34,13 @@ function createComponentBlock (options: ComponentBlockOptions): Block {
label,
pattern: new RegExp(`^<${id}(.*)>((.|\\n)*?)<\\/${id}>$`, 'm'),
fields: [
createField('object', {
props.length > 0 ? createField('object', {
name: 'props',
label: 'Properties',
required: false,
collapsed: true,
fields: props.map(fieldToSnakeCase),
}),
}) : undefined,
templateField != undefined ? createField('list', {
name: 'templates',
label: templateField.label,
Expand All @@ -63,7 +65,6 @@ function createComponentBlock (options: ComponentBlockOptions): Block {
}) : undefined,
].filter(n => n) as Block['fields'],
fromBlock: function (match): ComponentData {
console.log(match)
const props = match.at(1), slots = match.at(2)

return {
Expand All @@ -74,9 +75,7 @@ function createComponentBlock (options: ComponentBlockOptions): Block {
: {},
templates: slots != undefined
? slots.split('</template>').filter(str => str.length).map((slot) => {
// @ts-expect-error TODO: Look into moving to es2018 or higher
const results = /^<template #(.*)>(.*)/ms.exec(slot) ?? []
console.log([slots], slot, results)
const name = results.at(1)

return {
Expand Down Expand Up @@ -136,7 +135,6 @@ const customContainerBlock: Block = {
widget: 'markdown'
}
] satisfies DecapCmsField[],
// @ts-expect-error Needs flag to work
pattern: /^:::(\w+)(.*?)\n(.*?)\n^:::$/ms,
fromBlock: function (match): BlockFields {
return {
Expand All @@ -162,13 +160,7 @@ export default [
label: 'Steps',
labelSingular: 'step',
},
props: [
createField('string', {
name: 'color',
label: 'Color',
required: false,
}),
],
props: fields.stepsProperties,
}),
createComponentBlock({
id: 'tabs',
Expand All @@ -178,25 +170,7 @@ export default [
labelSingular: 'tab',
nameLabel: 'Id',
},
props: [
createField('list', {
name: 'tabs',
label: 'Tab names',
label_singular: 'name',
allow_add: true,
required: true,
}),
createField('string', {
name: 'startTab',
label: 'Start tab name',
required: false,
}),
createField('string', {
name: 'searchParam',
label: 'Search parameter',
required: false,
}),
]
props: fields.tabsProperties,
}),
createComponentBlock({
id: 'ActionBlock',
Expand Down
25 changes: 19 additions & 6 deletions docs/.vitepress/config/cms/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { type DecapCmsCollection } from 'vite-plugin-decap-cms'
import sidebar, { type Sidebar } from '../sidebar'

import {
createFeaturePageField,
createFeaturesField,
createHomePageFields,
createNotificationConfigFields,
createSiteConfigFields,
createTeamPageField,
} from './fields'
createTeamsField,
} from './fields/'

import {
createAdvancedCollections,
Expand Down Expand Up @@ -46,6 +47,14 @@ export default function (): DecapCmsCollection[] {
},
additionalFields: createHomePageFields(),
},
{
name: 'Notifications',
file: 'docs/.vitepress/config/data/notifications.json',
overwrites: {
deleted: true,
},
additionalFields: createNotificationConfigFields(),
},
], {
collection: {
create: false,
Expand All @@ -61,7 +70,11 @@ export default function (): DecapCmsCollection[] {
hidden: true,
},
additionalFields: [
createTeamPageField(),
createTeamsField({
name: 'teams',
label: 'Teams',
label_singular: 'team',
}),
]
},
{
Expand All @@ -71,7 +84,7 @@ export default function (): DecapCmsCollection[] {
hidden: true,
},
additionalFields: [
createFeaturePageField({
createFeaturesField({
name: 'collision_types',
label: 'Collision types',
label_singular: 'type',
Expand All @@ -85,7 +98,7 @@ export default function (): DecapCmsCollection[] {
hidden: true,
},
additionalFields: [
createFeaturePageField({
createFeaturesField({
name: 'next_actions',
label: 'Next actions',
label_singular: 'action',
Expand Down
29 changes: 29 additions & 0 deletions docs/.vitepress/config/cms/fields/components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createField } from 'vite-plugin-decap-cms'

export const stepsProperties = [
createField('string', {
name: 'color',
label: 'Color',
required: false,
}),
]

export const tabsProperties = [
createField('list', {
name: 'tabs',
label: 'Tab names',
label_singular: 'name',
allow_add: true,
required: true,
}),
createField('string', {
name: 'startTab',
label: 'Start tab name',
required: false,
}),
createField('string', {
name: 'searchParam',
label: 'Search parameter',
required: false,
}),
]
Loading

0 comments on commit 9d15646

Please sign in to comment.