feat: front matter in decks
This commit is contained in:
@@ -19,7 +19,7 @@ customElement("md-bg", { fit: "cover" }, (props, { element }) => {
|
|||||||
|
|
||||||
// 从父节点 article 的 data-src 获取当前 markdown 文件完整路径
|
// 从父节点 article 的 data-src 获取当前 markdown 文件完整路径
|
||||||
const articleEl = element?.closest('article') as HTMLElement;
|
const articleEl = element?.closest('article') as HTMLElement;
|
||||||
const articlePath = articleEl?.getAttribute('data-src') || '';
|
const articlePath = element?.closest('article[data-src]')?.getAttribute('data-src') || '';
|
||||||
|
|
||||||
// 解析相对路径
|
// 解析相对路径
|
||||||
const resolvedSrc = resolvePath(articlePath, rawSrc);
|
const resolvedSrc = resolvePath(articlePath, rawSrc);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { Layer, LayerConfig } from '../types';
|
import type { Layer, LayerConfig } from '../types';
|
||||||
|
import {CSV} from "../../utils/csv-loader";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析 layers 字符串
|
* 解析 layers 字符串
|
||||||
@@ -51,11 +52,14 @@ export function formatLayers(layers: LayerConfig[]): string {
|
|||||||
* 初始化图层配置
|
* 初始化图层配置
|
||||||
*/
|
*/
|
||||||
export function initLayerConfigs(
|
export function initLayerConfigs(
|
||||||
data: any[],
|
data: CSV<any>,
|
||||||
existingLayersStr: string
|
existingLayersStr: string
|
||||||
): LayerConfig[] {
|
): LayerConfig[] {
|
||||||
const parsed = parseLayers(existingLayersStr);
|
const parsed = parseLayers(existingLayersStr);
|
||||||
const allProps = Object.keys(data[0] || {}).filter(k => k !== 'label');
|
const allProps = Object.keys(data[0] || {}).filter(k => k !== 'label');
|
||||||
|
if(data.frontmatter){
|
||||||
|
allProps.push(...Object.keys(data.frontmatter));
|
||||||
|
}
|
||||||
|
|
||||||
return allProps.map(prop => {
|
return allProps.map(prop => {
|
||||||
const existing = parsed.find(l => l.prop === prop);
|
const existing = parsed.find(l => l.prop === prop);
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ export async function loadCSV<T = Record<string, string>>(path: string): Promise
|
|||||||
const csvResult = result as CSV<T>;
|
const csvResult = result as CSV<T>;
|
||||||
if (frontmatter) {
|
if (frontmatter) {
|
||||||
csvResult.frontmatter = frontmatter;
|
csvResult.frontmatter = frontmatter;
|
||||||
|
for(const each of result){
|
||||||
|
Object.setPrototypeOf(each, frontmatter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
csvCache.set(path, result);
|
csvCache.set(path, result);
|
||||||
|
|||||||
Reference in New Issue
Block a user