mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-14 23:28:30 +00:00
load titles from metadata in examples page
This commit is contained in:
parent
f9ad5f0d01
commit
52641db590
@ -1,6 +1,8 @@
|
||||
---
|
||||
import * as tunes from '../../../src/repl/tunes.mjs';
|
||||
import HeadCommon from '../../components/HeadCommon.astro';
|
||||
|
||||
import { getMetadata } from '../metadata_parser';
|
||||
---
|
||||
|
||||
<head>
|
||||
@ -12,7 +14,7 @@ import HeadCommon from '../../components/HeadCommon.astro';
|
||||
Object.entries(tunes).map(([name, tune]) => (
|
||||
<a class="rounded-md bg-slate-900 hover:bg-slate-700 cursor-pointer relative" href={`./#${btoa(tune)}`}>
|
||||
<div class="absolute w-full h-full flex justify-center items-center">
|
||||
<span class="bg-slate-800 p-2 rounded-md text-white">{name}</span>
|
||||
<span class="bg-slate-800 p-2 rounded-md text-white">{getMetadata(tune)['title'] || name}</span>
|
||||
</div>
|
||||
<img src={`./img/example-${name}.png`} />
|
||||
</a>
|
||||
|
||||
16
website/src/pages/metadata_parser.js
Normal file
16
website/src/pages/metadata_parser.js
Normal file
@ -0,0 +1,16 @@
|
||||
export function getMetadata(raw_code) {
|
||||
// https://stackoverflow.com/a/15123777
|
||||
const comment_regexp = /\/\*([\s\S]*?)\*\/|([^\\:]|^)\/\/(.*)$/gm;
|
||||
|
||||
const tag_regexp = /@([a-z]*):? (.*)/gm
|
||||
const tags = {};
|
||||
|
||||
for (const match of raw_code.matchAll(comment_regexp)) {
|
||||
const comment = match[1] ? match[1] : '' + match[3] ? match[3] : '';
|
||||
for (const tag_match of comment.trim().matchAll(tag_regexp)) {
|
||||
tags[tag_match[1]] = tag_match[2].trim()
|
||||
}
|
||||
}
|
||||
|
||||
return tags;
|
||||
}
|
||||
@ -1,19 +1,4 @@
|
||||
export function getMetadata(raw_code) {
|
||||
// https://stackoverflow.com/a/15123777
|
||||
const comment_regexp = /\/\*([\s\S]*?)\*\/|([^\\:]|^)\/\/(.*)$/gm;
|
||||
|
||||
const tag_regexp = /@([a-z]*):? (.*)/gm
|
||||
const tags = {};
|
||||
|
||||
for (const match of raw_code.matchAll(comment_regexp)) {
|
||||
const comment = match[1] ? match[1] : '' + match[3] ? match[3] : '';
|
||||
for (const tag_match of comment.trim().matchAll(tag_regexp)) {
|
||||
tags[tag_match[1]] = tag_match[2].trim()
|
||||
}
|
||||
}
|
||||
|
||||
return tags;
|
||||
}
|
||||
import { getMetadata } from '../metadata_parser';
|
||||
|
||||
export function getMyPatterns() {
|
||||
const my = import.meta.glob('../../../../my-patterns/**', { as: 'raw', eager: true });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user