tokens is not optional
drop join tokens
This commit is contained in:
1 parent
b945faded0
commit
9d31f30199
2 files changed
+2
-39
No files matched your search
+2
-3
@@ -9,7 +9,6 @@ import { MetaBuilder } from 'src/lib/meta'
|
||||
import { apiGet } from '@/next-lib'
|
||||
import { GetStaticProps, NextPage } from 'next'
|
||||
import { IBreadcumbsPart, IMeta, ITag, FileTokenData, Token } from '@/types'
|
||||
import { joinTokens } from 'src/lib/tokens'
|
||||
import { size, ext } from 'src/lib/file'
|
||||
import { Html } from 'src/components/Html'
|
||||
import { Youtube } from '@/components/Youtube'
|
||||
@@ -71,7 +70,7 @@ type Props = {
|
||||
date: string
|
||||
breadcrumb: IBreadcumbsPart[]
|
||||
meta?: IMeta
|
||||
tokens?: Token[]
|
||||
tokens: Token[]
|
||||
}
|
||||
|
||||
const Index: NextPage<Props> = props => (
|
||||
@@ -94,7 +93,7 @@ const Index: NextPage<Props> = props => (
|
||||
date={props.date ? new Date(props.date) : null}
|
||||
>
|
||||
<article className={'article'}>
|
||||
{joinTokens(props.tokens ?? []).map((x, i) => {
|
||||
{props.tokens.map((x, i) => {
|
||||
switch (x.token) {
|
||||
case 'text':
|
||||
return (
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import { TextToken, Token } from 'src/types'
|
||||
|
||||
export function joinTextTokens(tokens: TextToken[]): TextToken {
|
||||
return {
|
||||
token: 'text',
|
||||
data: tokens
|
||||
.map(x => x.data)
|
||||
.join('\n\n'),
|
||||
}
|
||||
}
|
||||
|
||||
export function joinTokens(tokens: Token[]): Token[] {
|
||||
let buffer: TextToken[] = []
|
||||
const result: Token[] = []
|
||||
|
||||
for (const token of tokens) {
|
||||
if (token.token === 'text') {
|
||||
buffer.push(token)
|
||||
continue
|
||||
}
|
||||
|
||||
const compiledToken = joinTextTokens(buffer)
|
||||
buffer = []
|
||||
|
||||
result.push(compiledToken)
|
||||
result.push(token)
|
||||
}
|
||||
|
||||
if (buffer.length) {
|
||||
result.push(
|
||||
joinTextTokens(buffer)
|
||||
)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in new issue
Block a user