Skip to content

Commit

Permalink
feat: process markdown into object
Browse files Browse the repository at this point in the history
  • Loading branch information
batleforc committed Sep 1, 2024
1 parent 0f5e221 commit 8f58a63
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 5 deletions.
20 changes: 20 additions & 0 deletions apps/front/src/component/Page/PageContent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script setup lang="ts">
import { TitleBlock } from '../../markdown';
import PageTitle from './PageTitle.vue';
defineProps<{
content: TitleBlock;
}>();
</script>

<template>
<div class="pageContent">
<PageTitle :value="content.value" :level="content.level" />
<p v-for="line in content.subBlocks" :key="line.value">{{ line.value }} - {{ line.type }}</p>
<div class="pageSubBlock">
<PageContent v-for="titleBlock in content.subTitleBlock" :key="titleBlock.value" :content="titleBlock" />
</div>
</div>
</template>

<style lang="scss"></style>
14 changes: 14 additions & 0 deletions apps/front/src/component/Page/PageMetadata.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script setup lang="ts">
import { DocHeader } from '@portfolio/api-client';
defineProps<{
metadata: DocHeader;
}>();
</script>

<template>
<div class="pageHeader">
<h1>{{ metadata.title }}</h1>
<p>{{ metadata.date }}</p>
</div>
</template>
22 changes: 18 additions & 4 deletions apps/front/src/component/Page/PageRender.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
<script setup lang="ts">
import { Page } from '@portfolio/api-client';
import PageMetadata from './PageMetadata.vue';
import PageContent from './PageContent.vue';
import { TitleBlock, transformContent } from '../../markdown';
import { ref, watch } from 'vue';
const props = defineProps<{
page: Page;
}>();
let contentBlock = ref<TitleBlock[]>(transformContent(props.page.content));
watch(() => props.page.content, (newValue, oldValue) => {
if (newValue !== oldValue) {
contentBlock.value = transformContent(newValue);
}
})
</script>

<template>
<div>
<h1>{{ page.name }}</h1>
<p>{{ page.content }}</p>
<div class="pageView">
<PageMetadata :metadata="page.metadata" />
<div class="pageContent">
<PageContent v-for="block in contentBlock" :key="block.value" :content="block" />
</div>
</div>
</template>
37 changes: 37 additions & 0 deletions apps/front/src/component/Page/PageTitle.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script setup lang="ts">
defineProps<{
value: string,
level: number,
}>();
</script>

<template>
<div class="pageBlockTitle">
<h1 class="pageBlockTitleH pageBlockTitleH1" v-if="level === 1">{{ value }}</h1>
<h2 class="pageBlockTitleH pageBlockTitleH2" v-else-if="level === 2">{{ value }}</h2>
<h3 class="pageBlockTitleH pageBlockTitleH3" v-else-if="level === 3">{{ value }}</h3>
<h4 class="pageBlockTitleH pageBlockTitleH4" v-else>{{ value }}</h4>
</div>
</template>

<style lang="scss">
.pageBlockTitleH {
@apply m-2 tracking-wide;
}
.pageBlockTitleH1 {
@apply font-bold text-5xl;
}
.pageBlockTitleH2 {
@apply font-bold text-4xl;
}
.pageBlockTitleH3 {
@apply font-semibold text-3xl;
}
.pageBlockTitleH4 {
@apply font-medium text-2xl;
}
</style>
74 changes: 74 additions & 0 deletions apps/front/src/markdown/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
export enum BlockType {
string = 'string',
title = 'title',
startEndCodeBlock = 'startEndCodeBlock',
}

export type Block = {
type: BlockType;
value: string;
};

export class TitleBlock {
type: BlockType = BlockType.title;
level = 0;
value = '';
subBlocks: Block[] = [];
subTitleBlock: TitleBlock[] = [];

constructor(value: string) {
this.value = value.replace(new RegExp('#{0,}'), '').trim();
this.level = value.split('').filter((char: string) => char === '#').length;
}

appendTitleBlock = (param: TitleBlock) => {
if (param.level - 1 === this.level) {
this.subTitleBlock.push(param);
} else if (this.subTitleBlock.length > 0) {
this.subTitleBlock[this.subTitleBlock.length - 1].appendTitleBlock(param);
} else {
this.subTitleBlock.push(param);
}
};
appendBlock = (block: Block) => {
if (this.subTitleBlock.length > 0) {
this.subTitleBlock[this.subTitleBlock.length - 1].appendBlock(block);
} else {
this.subBlocks.push(block);
}
};
}

export const transformContent = (content: string): TitleBlock[] => {
const titleBlocks: TitleBlock[] = [];
const lines = content.split('\n');
lines.forEach((line) => {
// Title
if (line.trim() === '') return;
if (line.startsWith('#')) {
const titleBlock = new TitleBlock(line);
if (
titleBlocks.length === 0 ||
titleBlocks[titleBlocks.length - 1].level === titleBlock.level
)
titleBlocks.push(titleBlock);
if (titleBlocks[titleBlocks.length - 1].level < titleBlock.level) {
titleBlocks[titleBlocks.length - 1].appendTitleBlock(titleBlock);
}
} else {
const block: Block = {
type: BlockType.string,
value: line,
};
if (line.startsWith('```')) {
block.type = BlockType.startEndCodeBlock;
}
if (titleBlocks.length === 0) {
titleBlocks.push(new TitleBlock(''));
}
titleBlocks[titleBlocks.length - 1].appendBlock(block);
}
});
console.log(titleBlocks);
return titleBlocks;
};
28 changes: 27 additions & 1 deletion cicd/Readme.md → folio_content/content/cicd/portfolio-cicd.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
# Monofolio CICD
---
date: 2024-08-09T22:51:00Z
title: "Monofolio-CICD"
description: |
Monofolio CICD
spec:
blog: false
project: true
doc: true
tags:
- project
- Kube
- continuous-update
- GitOps
techno:
- Kubernetes
- ArgoCD
- Helm
- Terraform
- Gitea
- Tekton
- Kustomize
---

## Goal

Expand Down Expand Up @@ -34,6 +56,10 @@
- The Release flow is executed and the `beta` version is deployed.
- If the `beta` version is stable, a new tag is created and the `production` version is deployed.

#### Test

test 12345

```mermaid
flowchart TD;
subgraph "Development flow"
Expand Down

0 comments on commit 8f58a63

Please sign in to comment.