Skip to content

Commit

Permalink
feat(v2): bootstrap blog post page and card (#2584)
Browse files Browse the repository at this point in the history
* feat(v2): init the blog post card

* feat(v2): Update card design

* chore(v2): remove unused dependency

* feat(v2): add post list

* feat(v2): improve html tags

* chore(v2): run prettier

* feat(v2): remove old tag

* feat(v2): apply suggestions
  • Loading branch information
fanny authored Apr 12, 2020
1 parent 9c1abcd commit f61b92d
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
id: hola
title: Hola
author: Gao Wei
author_title: Docusaurus Core Team
author_url: https://github.com/wgao19
author_image_url: https://avatars1.githubusercontent.com/u/2055384?v=4
tags: [hola, docusaurus]
---

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
id: hello-world
title: Hello
author: Endilie Yacop Sucipto
author_title: Maintainer of Docusaurus
author_url: https://github.com/endiliey
author_image_url: https://avatars1.githubusercontent.com/u/17883920?s=460&v=4
tags: [hello, docusaurus]
---

Welcome to this blog. This blog is created with [**Docusaurus 2 alpha**](https://v2.docusaurus.io/).

<!--truncate-->

This is a test post.

A whole bunch of other information.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
id: welcome
title: Welcome
author: Yangshun Tay
author_title: Front End Engineer @ Facebook
author_url: https://github.com/yangshun
author_image_url: https://avatars0.githubusercontent.com/u/1315101?s=400&v=4
tags: [facebook, hello, docusaurus]
---

Blog features are powered by the blog plugin. Simply add files to the `blog` directory. It supports tags as well!

Delete the whole directory if you don't want the blog features. As simple as that!
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ module.exports = {
copyright: `Copyright © ${new Date().getFullYear()} My Project, Inc. Built with Docusaurus.`,
},
},
presets: [['@docusaurus/preset-bootstrap', {}]],
presets: [['@docusaurus/preset-bootstrap']],
};
2 changes: 2 additions & 0 deletions packages/docusaurus-preset-bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"access": "public"
},
"dependencies": {
"@docusaurus/theme-bootstrap": "^2.0.0-alpha.50",
"@docusaurus/plugin-content-blog": "^2.0.0-alpha.50",
"@docusaurus/plugin-content-pages": "^2.0.0-alpha.50"
},
"peerDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion packages/docusaurus-preset-bootstrap/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
module.exports = function preset(context, opts = {}) {
return {
themes: [['@docusaurus/theme-bootstrap', opts.theme]],
plugins: [['@docusaurus/plugin-content-pages', opts.pages]],
plugins: [
['@docusaurus/plugin-content-pages', opts.pages],
['@docusaurus/plugin-content-blog', opts.blog],
],
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import BlogPostCard from '@theme/BlogPostItem';

function BlogListPage(props) {
const {items} = props;

return (
<div className="container my-5">
<div className="row">
{items.map(({content: BlogPostContent}) => (
<div className="col col-8 offset-2 mb-5">
<BlogPostCard
key={BlogPostContent.metadata.permalink}
frontMatter={BlogPostContent.frontMatter}
metadata={BlogPostContent.metadata}
truncated={BlogPostContent.metadata.truncated}
/>
</div>
))}
</div>
</div>
);
}

export default BlogListPage;
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';

const MONTHS = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];

function BlogPostItem(props) {
const {frontMatter, metadata, truncated} = props;

const {date, readingTime} = metadata;
const {author, title} = frontMatter;

const authorURL = frontMatter.author_url || frontMatter.authorURL;
const authorImageURL =
frontMatter.author_image_url || frontMatter.authorImageURL;

const match = date.substring(0, 10).split('-');
const year = match[0];
const month = MONTHS[parseInt(match[1], 10) - 1];
const day = parseInt(match[2], 10);

return (
<article className="card h-100">
<div className="row no-gutters rows-col-2 m-3">
<div className="col-xs mr-3">
{authorImageURL && (
<img style={{width: '50px'}} src={authorImageURL} alt={author} />
)}
</div>
<div className="col">
{author && (
<h5>
<a href={authorURL} alt={author}>
{author}
</a>
</h5>
)}
<time
className="card-subtitle mb-md-4 font-weight-light"
dateTime={date}>
{month} {day}, {year}{' '}
</time>
</div>
</div>

<div className="card-body">
<h3 className="card-title text-primary">{title}</h3>
<p className="lead">Markdown content</p>
</div>

<div className="text-right m-3">
{readingTime && (
<small className={truncated ? 'mx-3' : ''}>
{Math.ceil(readingTime)} min read
</small>
)}
{truncated && (
<a href="https://github.com/" className="stretched-link">
Read more
</a>
)}
</div>
</article>
);
}

export default BlogPostItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

export default () => {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

export default () => {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

export default () => {};

0 comments on commit f61b92d

Please sign in to comment.