feat(v2): add edit url in post page (#2524)

* Add edit page url in docs

* feat(v2): Create EditPage component

* feat(v2): Improve component

* Add test

* çhore(v2): update description

* çhore(v2): update url

* fix(v2): test

* fix(v2): test

* feat(v2): change the prop of EditPage component

* chore(v2): Remove packages

* feat(v2): Update old tests

* chore(v2): fix package

* fix(v2): fix editUrl

* docs(v2): document editUrl

* --

* --

Co-authored-by: Yangshun Tay <tay.yang.shun@gmail.com>
This commit is contained in:
Fanny 2020-04-05 06:34:48 -03:00 committed by GitHub
parent 7bc7241ee4
commit 5e664a1f26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 72 additions and 12 deletions

View file

@ -11,7 +11,12 @@ import path from 'path';
import readingTime from 'reading-time';
import {Feed} from 'feed';
import {PluginOptions, BlogPost, DateLink} from './types';
import {parse, normalizeUrl, aliasedSitePath} from '@docusaurus/utils';
import {
parse,
normalizeUrl,
aliasedSitePath,
getEditUrl,
} from '@docusaurus/utils';
import {LoadContext} from '@docusaurus/types';
export function truncate(fileString: string, truncateMarker: RegExp) {
@ -86,7 +91,13 @@ export async function generateBlogPosts(
{siteConfig, siteDir}: LoadContext,
options: PluginOptions,
) {
const {include, routeBasePath, truncateMarker, showReadingTime} = options;
const {
include,
routeBasePath,
truncateMarker,
showReadingTime,
editUrl,
} = options;
if (!fs.existsSync(blogDir)) {
return [];
@ -103,8 +114,12 @@ export async function generateBlogPosts(
blogFiles.map(async (relativeSource: string) => {
const source = path.join(blogDir, relativeSource);
const aliasedSource = aliasedSitePath(source, siteDir);
const refDir = path.parse(blogDir).dir;
const relativePath = path.relative(refDir, source);
const blogFileName = path.basename(relativeSource);
const editBlogUrl = getEditUrl(relativePath, editUrl);
const fileString = await fs.readFile(source, 'utf-8');
const {frontMatter, content, excerpt} = parse(fileString);
@ -140,6 +155,7 @@ export async function generateBlogPosts(
routeBasePath,
frontMatter.id || toUrl({date, link: linkName}),
]),
editUrl: editBlogUrl,
source: aliasedSource,
description: frontMatter.description || excerpt,
date,