text component updates + performance improved
This commit is contained in:
1 parent
968da68929
commit
df229b5e8c
5 files changed
+11
-26
No files matched your search
@@ -2,7 +2,6 @@ import Head from 'next/head'
|
|||||||
import { App } from 'src/components/App'
|
import { App } from 'src/components/App'
|
||||||
import { tail } from 'lodash'
|
import { tail } from 'lodash'
|
||||||
import { Page } from 'src/components/Page'
|
import { Page } from 'src/components/Page'
|
||||||
import { Markdown } from 'src/components/Markdown'
|
|
||||||
import { Meta } from 'src/components/Meta'
|
import { Meta } from 'src/components/Meta'
|
||||||
import { MetaBuilder } from 'src/lib/meta'
|
import { MetaBuilder } from 'src/lib/meta'
|
||||||
import { apiGet } from '@/next-lib'
|
import { apiGet } from '@/next-lib'
|
||||||
@@ -80,14 +79,6 @@ const Index: NextPage<Props> = props => {
|
|||||||
<article className={'article'}>
|
<article className={'article'}>
|
||||||
{props.tokens.map((x, i) => {
|
{props.tokens.map((x, i) => {
|
||||||
switch (x.token) {
|
switch (x.token) {
|
||||||
case 'text':
|
|
||||||
return (
|
|
||||||
<Markdown
|
|
||||||
key={i}
|
|
||||||
data={x.data}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
|
|
||||||
case 'html':
|
case 'html':
|
||||||
return (
|
return (
|
||||||
<Html
|
<Html
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
import { Html } from 'src/components/Html'
|
|
||||||
import { memo } from 'react'
|
|
||||||
import { typograf, markdownToHtml } from 'src/lib/text'
|
|
||||||
|
|
||||||
export type MarkdownProps = {
|
|
||||||
data: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Markdown: React.SFC<MarkdownProps> = memo(props => (
|
|
||||||
<Html
|
|
||||||
html={typograf(markdownToHtml(props.data))}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
import { ImageDefinition, IMenu, IPage, ITag, PageCardDto, Token } from "@/types";
|
import { ImageDefinition, IMenu, IPage, ITag, PageCardDto, Token } from "@/types";
|
||||||
import { asItem } from "./lib";
|
import { asItem } from "./lib";
|
||||||
import { StrapiComponentEmbed, StrapiComponent, StrapiHome, StrapiPage, StrapiPageCard, StrapiTag, StrapiMedia, StrapiMenu } from "./types";
|
import { StrapiComponentEmbed, StrapiComponent, StrapiHome, StrapiPage, StrapiPageCard, StrapiTag, StrapiMedia, StrapiMenu } from "./types";
|
||||||
|
import { typograf, markdownToHtml } from 'src/lib/text'
|
||||||
|
|
||||||
|
const md = (text: string) => typograf(markdownToHtml(text))
|
||||||
|
|
||||||
export function createPageUrls(pages: StrapiPage[]) {
|
export function createPageUrls(pages: StrapiPage[]) {
|
||||||
return {
|
return {
|
||||||
@@ -42,8 +45,8 @@ export function createPageTokens(components: StrapiComponent[]): Token[] {
|
|||||||
switch (component.__component) {
|
switch (component.__component) {
|
||||||
case 'hudozka.text': {
|
case 'hudozka.text': {
|
||||||
return {
|
return {
|
||||||
token: 'text',
|
token: 'html',
|
||||||
data: component.text,
|
data: md(component.text),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,8 +143,8 @@ export function createPage(res: StrapiPage | StrapiPage[]): IPage | null {
|
|||||||
cover,
|
cover,
|
||||||
tokens: [
|
tokens: [
|
||||||
{
|
{
|
||||||
token: 'text',
|
token: 'html',
|
||||||
data: `# ${item.title}`,
|
data: md(`# ${item.title}`),
|
||||||
},
|
},
|
||||||
|
|
||||||
...createPageTokens(item.content)
|
...createPageTokens(item.content)
|
||||||
|
|||||||
@@ -25,11 +25,13 @@
|
|||||||
|
|
||||||
.article li {
|
.article li {
|
||||||
margin-bottom: var(--size-s);
|
margin-bottom: var(--size-s);
|
||||||
|
max-width: var(--text-max-width);
|
||||||
}
|
}
|
||||||
|
|
||||||
.article p {
|
.article p {
|
||||||
margin-bottom: var(--size-m);
|
margin-bottom: var(--size-m);
|
||||||
line-height: var(--article-line-height);
|
line-height: var(--article-line-height);
|
||||||
|
max-width: var(--text-max-width);
|
||||||
}
|
}
|
||||||
|
|
||||||
.article blockquote {
|
.article blockquote {
|
||||||
|
|||||||
@@ -51,6 +51,8 @@
|
|||||||
--content-wide-width: 100%;
|
--content-wide-width: 100%;
|
||||||
--content-wide-margin: var(--size-l) var(--size-xl);
|
--content-wide-margin: var(--size-l) var(--size-xl);
|
||||||
|
|
||||||
|
--text-max-width: 800px;
|
||||||
|
|
||||||
/* KAZIMIR */
|
/* KAZIMIR */
|
||||||
--kazimir-caption-margin: 0px;
|
--kazimir-caption-margin: 0px;
|
||||||
--picture-wide-increase: 100px;
|
--picture-wide-increase: 100px;
|
||||||
|
|||||||
Reference in new issue
Block a user