-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c342d5
commit 10491f5
Showing
7 changed files
with
194 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script setup lang="ts"> | ||
import {data as SamplesData} from "../data/playground/PlaygroundSamples.data"; | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<span class="description">Examples </span> | ||
<select class="select-box"> | ||
<option disabled hidden selected>Select an example...</option> | ||
<optgroup :label="chapter.name" v-for="chapter in SamplesData.chapters"> | ||
<option v-for="sample in chapter.samples">{{ sample.name }}</option> | ||
</optgroup> | ||
</select> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.description { | ||
font-weight: 400; | ||
font-size: 19px; | ||
} | ||
.select-box { | ||
appearance: menulist-button; | ||
height: 32px; | ||
border: 1px solid #ced4da; | ||
border-radius: 8px; | ||
padding: 4px 4px; | ||
font-size: 18px; | ||
line-height: 1.1; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<script setup lang="ts"> | ||
interface Props { | ||
content?: string | ||
} | ||
const { | ||
content = '' | ||
} = defineProps<Props>() | ||
</script> | ||
|
||
<template> | ||
<div class="container" v-html="content"></div> | ||
</template> | ||
|
||
<style scoped> | ||
.container { | ||
width: 100%; | ||
min-height: 40%; | ||
margin: 16px 0; | ||
padding: 16px; | ||
border-radius: 8px; | ||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); | ||
font-family: Consolas, serif; | ||
overflow: auto; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
<div class="container"> | ||
<div> | ||
<slot name="left"></slot> | ||
</div> | ||
<div> | ||
<slot name="right"></slot> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.container { | ||
height: 32px; | ||
display: flex; | ||
justify-content: space-between; | ||
margin-bottom: 8px; | ||
padding: 0 4px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {defineLoader} from 'vitepress' | ||
import {readFile} from 'node:fs/promises' | ||
import {basename, parse} from 'node:path' | ||
|
||
interface SampleData { | ||
chapter: string, | ||
name: string, | ||
code: string, | ||
} | ||
|
||
interface Sample { | ||
name: string, | ||
code: string, | ||
} | ||
|
||
interface Chapter { | ||
name: string | ||
samples: Sample[] | ||
} | ||
|
||
export interface Data { | ||
chapters: Chapter[] | ||
} | ||
|
||
declare const data: Data | ||
export {data} | ||
|
||
export default defineLoader({ | ||
watch: ['./samples/**/*.fk'], | ||
async load(watchedFiles): Promise<Data> { | ||
const sampleData = await Promise.all(watchedFiles.map(loadSample)) | ||
const chapterMap = new Map<string, Chapter>(); | ||
for (const sd of sampleData) { | ||
const key = sd.chapter | ||
if (!chapterMap.has(key)) { | ||
chapterMap.set(key, { | ||
name: key, | ||
samples: [] | ||
}) | ||
} | ||
|
||
const chapter = chapterMap.get(key) | ||
chapter.samples.push(sd) | ||
} | ||
|
||
return {chapters: Array.from(chapterMap.values())} | ||
} | ||
}) | ||
|
||
async function loadSample(path: string): Promise<SampleData> { | ||
const code = await readFile(path, 'utf-8') | ||
|
||
const parsedPath = parse(path) | ||
const sampleName = parsedPath.name | ||
const chapterName = basename(parsedPath.dir) | ||
|
||
return { | ||
chapter: chapterName, | ||
name: sampleName, | ||
code | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
docs/.vitepress/data/playground/samples/function/closure.fk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
let cnt = 0; | ||
|
||
let add = fn() { | ||
cnt = cnt + 1; | ||
cnt; | ||
}; | ||
|
||
print(add()); | ||
print("\n"); | ||
print(add()); | ||
print("\n"); | ||
print(add()); |
11 changes: 11 additions & 0 deletions
11
docs/.vitepress/data/playground/samples/loop/nine-nine-multiplication-table.fk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
for (let i = 1; i < 10; i = i + 1) { | ||
for (let j = 1; j <= i; j = j + 1) { | ||
print(j); | ||
print("*"); | ||
print(i); | ||
print("="); | ||
print(j*i); | ||
print(" "); | ||
} | ||
print("\n"); | ||
} |