refactor: poetry content to array

This commit is contained in:
Tristan 2019-09-28 10:52:11 +08:00
parent 452de2c858
commit c9443088b0
3 changed files with 7 additions and 6 deletions

View File

@ -35,7 +35,7 @@ const Poetry = ({ content = '', author = '', title = '' }) => {
<h2>
{author} · {title}
</h2>
<p className="line">{content.replace(/[|。|||、]/g, ' ').trim()}</p>
<p className="line">{content.join(' ')}</p>
</Wrapper>
);
};

View File

@ -105,14 +105,11 @@ const Preview = ({ name, color, figure = 'default.png?width=8rem', closePreview
const figureO = +(params.get('o') || 1);
const currPoetry = JSON.parse(localStorage.getItem('POETRY'));
const { author, title, content } = currPoetry;
const lines = content
.replace(/[|。||]/g, ' ')
.trim()
.split(' ');
return (
<Wrapper id="PREVIEW" bgColor={color}>
<article style={{ color: oppositeColor }} className={'poetry'}>
{lines.map(line => {
{content.map(line => {
return (
<p key={line} className="line">
{line}

View File

@ -86,6 +86,10 @@ const usePoetry = dep => {
author: result.data.origin.author,
title: result.data.origin.title
};
obj.content = obj.content
.replace(/[|。|||、]/g, ' ')
.trim()
.split(' ');
setPoetry(obj);
localStorage.setItem('POETRY', JSON.stringify(obj));
},