support config urls and direct config embedding in project lists
This commit is contained in:
parent
e1611b95f4
commit
f9c84c53f4
5 changed files with 66 additions and 5 deletions
|
@ -2,6 +2,11 @@ import DOMPurify from 'dompurify'
|
|||
import { marked } from 'marked'
|
||||
import yaml from 'js-yaml'
|
||||
|
||||
import type {
|
||||
EntryWithConfig,
|
||||
EntryWithContent,
|
||||
} from '@goldenwere/mackenzii-types/src/content/templates/shared'
|
||||
|
||||
/**
|
||||
* Config used for DOMPurify.
|
||||
* This config allows for most HTML elements and a handful of attributes
|
||||
|
@ -123,6 +128,36 @@ export const fetchAndParseMarkdown = async (path: string) => {
|
|||
return marked.parse(document)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches content for an entry
|
||||
* @param entry the entry whose content should be fetched
|
||||
* @returns the markdown content for the entry
|
||||
*/
|
||||
export const fetchContent = async (entry: EntryWithContent) => {
|
||||
if (!!entry.content) {
|
||||
return entry.content
|
||||
} else if (!!entry.contentUrl) {
|
||||
return fetchAndParseMarkdown(entry.contentUrl)
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches config for an entry
|
||||
* @param entry the entry whose config should be fetched
|
||||
* @returns the config object for the entry
|
||||
*/
|
||||
export const fetchConfig = async <T>(entry: EntryWithConfig<T>) => {
|
||||
if (!!entry.config) {
|
||||
return entry.config as T
|
||||
} else if (!!entry.configUrl) {
|
||||
return fetchAndParseYaml(entry.configUrl) as T
|
||||
}
|
||||
|
||||
return {} as T
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches content type from an image
|
||||
* @param path the path of the file to check
|
||||
|
|
|
@ -6,7 +6,7 @@ import type {
|
|||
ProjectListDefinition,
|
||||
} from '@goldenwere/mackenzii-types'
|
||||
|
||||
import { fetchAndParseYaml } from 'src/utilities/fetch'
|
||||
import { fetchAndParseYaml, fetchConfig } from 'src/utilities/fetch'
|
||||
import { getCurrentRoute } from 'src/utilities/vuetils'
|
||||
import { useRouteStore } from 'src/routes'
|
||||
|
||||
|
@ -55,7 +55,7 @@ onMounted(async () => {
|
|||
projectIds.value = Object.keys(config.value.projects)
|
||||
for (let i = 0; i < projectIds.value.length; ++i) {
|
||||
const id = projectIds.value[i]
|
||||
projects.value[id] = await fetchAndParseYaml(config.value.projects[id].config)
|
||||
projects.value[id] = await fetchConfig(config.value.projects[id])
|
||||
}
|
||||
document.title = routeConfig.fullTitle
|
||||
ready.value = true
|
||||
|
|
|
@ -7,7 +7,7 @@ import type {
|
|||
RoutedWindow,
|
||||
} from '@goldenwere/mackenzii-types'
|
||||
|
||||
import { fetchAndParseMarkdown, fetchAndParseYaml } from 'src/utilities/fetch'
|
||||
import { fetchAndParseYaml, fetchConfig, fetchContent } from 'src/utilities/fetch'
|
||||
import { getCurrentRoute } from 'src/utilities/vuetils'
|
||||
import { useRouteStore } from 'src/routes'
|
||||
|
||||
|
@ -29,8 +29,8 @@ const routeSubConfig = routeStore._routes[currentRoute.path]
|
|||
|
||||
onMounted(async () => {
|
||||
const config = await fetchAndParseYaml<ProjectList>(routeConfig.config)
|
||||
info.value = await fetchAndParseYaml<ProjectListingInfo>(config.projects[currentRoute.query.id as string].config)
|
||||
const md = await fetchAndParseMarkdown(config.projects[currentRoute.query.id as string].content)
|
||||
info.value = await fetchConfig(config.projects[currentRoute.query.id as string])
|
||||
const md = await fetchContent(config.projects[currentRoute.query.id as string])
|
||||
content.value = md
|
||||
document.title = routeSubConfig.fullTitle?.replace('$PROJECT', info.value.title)
|
||||
routeStore.setBreadcrumbs(currentRoute, info.value.title)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue