-
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
Showing
6 changed files
with
190 additions
and
5 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,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> |
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,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> |
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 |
---|---|---|
@@ -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> |
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,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> |
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,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; | ||
}; |
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