load titles from metadata in examples page
This commit is contained in:
parent
f9ad5f0d01
commit
52641db590
3 changed files with 20 additions and 17 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
---
|
---
|
||||||
import * as tunes from '../../../src/repl/tunes.mjs';
|
import * as tunes from '../../../src/repl/tunes.mjs';
|
||||||
import HeadCommon from '../../components/HeadCommon.astro';
|
import HeadCommon from '../../components/HeadCommon.astro';
|
||||||
|
|
||||||
|
import { getMetadata } from '../metadata_parser';
|
||||||
---
|
---
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
|
|
@ -12,7 +14,7 @@ import HeadCommon from '../../components/HeadCommon.astro';
|
||||||
Object.entries(tunes).map(([name, tune]) => (
|
Object.entries(tunes).map(([name, tune]) => (
|
||||||
<a class="rounded-md bg-slate-900 hover:bg-slate-700 cursor-pointer relative" href={`./#${btoa(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">
|
<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>
|
</div>
|
||||||
<img src={`./img/example-${name}.png`} />
|
<img src={`./img/example-${name}.png`} />
|
||||||
</a>
|
</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) {
|
import { getMetadata } from '../metadata_parser';
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getMyPatterns() {
|
export function getMyPatterns() {
|
||||||
const my = import.meta.glob('../../../../my-patterns/**', { as: 'raw', eager: true });
|
const my = import.meta.glob('../../../../my-patterns/**', { as: 'raw', eager: true });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue