-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(v2): linkify blog posts * Fix tests
- Loading branch information
Showing
8 changed files
with
161 additions
and
12 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
...s__/__fixtures__/website/blog-with-ref/2018-12-14-Happy-First-Birthday-Slash.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Happy 1st Birthday Slash! | ||
--- | ||
|
||
pattern name |
5 changes: 5 additions & 0 deletions
5
...us-plugin-content-blog/src/__tests__/__fixtures__/website/blog-with-ref/post.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: This post links to another one! | ||
--- | ||
|
||
[Linked post](2018-12-14-Happy-First-Birthday-Slash.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/linkify.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`transform to correct link 1`] = ` | ||
"--- | ||
title: This post links to another one! | ||
--- | ||
[Linked post](/blog/2018/12/14/Happy-First-Birthday-Slash)" | ||
`; |
56 changes: 56 additions & 0 deletions
56
packages/docusaurus-plugin-content-blog/src/__tests__/linkify.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import {linkify} from '../blogUtils'; | ||
import {BlogPost} from '../types'; | ||
|
||
const sitePath = path.join(__dirname, '__fixtures__', 'website'); | ||
const blogPath = path.join(sitePath, 'blog-with-ref'); | ||
const pluginDir = 'blog-with-ref'; | ||
const blogPosts: BlogPost[] = [ | ||
{ | ||
id: 'Happy 1st Birthday Slash!', | ||
metadata: { | ||
permalink: '/blog/2018/12/14/Happy-First-Birthday-Slash', | ||
source: path.join( | ||
'@site', | ||
pluginDir, | ||
'2018-12-14-Happy-First-Birthday-Slash.md', | ||
), | ||
title: 'Happy 1st Birthday Slash!', | ||
description: `pattern name`, | ||
date: new Date('2018-12-14'), | ||
tags: [], | ||
prevItem: { | ||
permalink: '/blog/2019/01/01/date-matter', | ||
title: 'date-matter', | ||
}, | ||
truncated: false, | ||
}, | ||
}, | ||
]; | ||
|
||
const transform = filepath => { | ||
const content = fs.readFileSync(filepath, 'utf-8'); | ||
const transformedContent = linkify(content, sitePath, blogPath, blogPosts); | ||
return [content, transformedContent]; | ||
}; | ||
|
||
test('transform to correct link', () => { | ||
const post = path.join(blogPath, 'post.md'); | ||
const [content, transformedContent] = transform(post); | ||
expect(transformedContent).toMatchSnapshot(); | ||
expect(transformedContent).toContain( | ||
'](/blog/2018/12/14/Happy-First-Birthday-Slash', | ||
); | ||
expect(transformedContent).not.toContain( | ||
'](2018-12-14-Happy-First-Birthday-Slash.md)', | ||
); | ||
expect(content).not.toEqual(transformedContent); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters