[www] Article updated, added rendering of article tags
This commit is contained in:
1 parent
b4337eec52
commit
1f45596dd3
5 files changed
+70
-9
No files matched your search
@@ -2,13 +2,31 @@ const React = require('react')
|
|||||||
const getHtml = require('../lib/component').getHtml
|
const getHtml = require('../lib/component').getHtml
|
||||||
const dateFormat = require('../lib/date').dateFormat
|
const dateFormat = require('../lib/date').dateFormat
|
||||||
|
|
||||||
const Head = ({date, children}) => (
|
const Tag = ({children}) => (
|
||||||
|
<li className="ArticleTags-Item">
|
||||||
|
{children}
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
|
||||||
|
const TagList = ({tags}) => (
|
||||||
|
<ul className="ArticleTags">
|
||||||
|
{tags.map((x, i) => (
|
||||||
|
<Tag key={i}># {x.name}</Tag>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)
|
||||||
|
|
||||||
|
const Head = ({date, tags, children}) => (
|
||||||
<header className="Article-Head">
|
<header className="Article-Head">
|
||||||
<h1>{children}</h1>
|
<h1>{children}</h1>
|
||||||
|
|
||||||
{!date ? null : (
|
{!date ? null : (
|
||||||
<p className="date">{dateFormat(date)}</p>
|
<p className="date">{dateFormat(date)}</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{!tags.length ? null : (
|
||||||
|
<TagList tags={tags}/>
|
||||||
|
)}
|
||||||
</header>
|
</header>
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,14 +39,17 @@ const Share = () => (
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
const Article = ({children, data, url, title, date, shareable}) => (
|
const Article = ({children, article, shareable}) => (
|
||||||
<article className="Article">
|
<article className="Article">
|
||||||
<Head date={date}>
|
<Head
|
||||||
{title}
|
date={article.date}
|
||||||
|
tags={article.tags}
|
||||||
|
>
|
||||||
|
{article.title}
|
||||||
</Head>
|
</Head>
|
||||||
|
|
||||||
<div className="Article-Body">
|
<div className="Article-Body">
|
||||||
{children || getHtml(data)}
|
{children || getHtml(article.post)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!shareable ? null : (
|
{!shareable ? null : (
|
||||||
|
|||||||
+11
-1
@@ -5,6 +5,10 @@ const {find, findOne, total} = require('../lib/store')
|
|||||||
|
|
||||||
const store = () => Data.getStore(Article)
|
const store = () => Data.getStore(Article)
|
||||||
|
|
||||||
|
function make(C) {
|
||||||
|
return x => new C(x)
|
||||||
|
}
|
||||||
|
|
||||||
class Article {
|
class Article {
|
||||||
static async find(query, options = {}) {
|
static async find(query, options = {}) {
|
||||||
const items = await find(store(), query, options)
|
const items = await find(store(), query, options)
|
||||||
@@ -41,7 +45,7 @@ class Article {
|
|||||||
this.date = data.date
|
this.date = data.date
|
||||||
this.title = data.title
|
this.title = data.title
|
||||||
this.until = data.until
|
this.until = data.until
|
||||||
this.tags = data.tags
|
this.tags = (data.tags || []).map(make(Tag))
|
||||||
this.content = data.content
|
this.content = data.content
|
||||||
this.hash = data.hash
|
this.hash = data.hash
|
||||||
this.type = data.type
|
this.type = data.type
|
||||||
@@ -75,6 +79,12 @@ class Article {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Tag {
|
||||||
|
constructor(tag) {
|
||||||
|
this.name = tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const previewFromImage = (imgs = []) => imgs.length
|
const previewFromImage = (imgs = []) => imgs.length
|
||||||
? imgs[0]
|
? imgs[0]
|
||||||
: null
|
: null
|
||||||
|
|||||||
@@ -112,9 +112,7 @@ async function renderArticle(id) {
|
|||||||
const Component = (
|
const Component = (
|
||||||
<div className="content content_thin">
|
<div className="content content_thin">
|
||||||
<ArticleComponent
|
<ArticleComponent
|
||||||
title={article.title}
|
article={article}
|
||||||
date={article.date}
|
|
||||||
data={article.post}
|
|
||||||
shareable={true}
|
shareable={true}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
@import "../variables";
|
||||||
|
|
||||||
|
.ArticleTags {
|
||||||
|
--article-card-width: 30%;
|
||||||
|
--article-card-margin: var(--single-margin) var(--half-margin);
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
list-style: none;
|
||||||
|
|
||||||
|
&-Item {
|
||||||
|
background: #99bde1;
|
||||||
|
padding: 3px 9px;
|
||||||
|
|
||||||
|
font-size: 14px;
|
||||||
|
color: #393939;
|
||||||
|
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-Item {
|
||||||
|
margin-right: 0.5em;
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
margin-right: 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
@import "components/ArticleCard";
|
@import "components/ArticleCard";
|
||||||
@import "components/ArticleCardList";
|
@import "components/ArticleCardList";
|
||||||
|
@import "components/ArticleTags";
|
||||||
@import "components/CollectiveImage";
|
@import "components/CollectiveImage";
|
||||||
@import "components/PersonCard";
|
@import "components/PersonCard";
|
||||||
@import "components/PersonCardList";
|
@import "components/PersonCardList";
|
||||||
|
|||||||
Reference in new issue
Block a user