From 0400d40a1acf7b82769584d2aa3deae33fc43432 Mon Sep 17 00:00:00 2001 From: endiliey Date: Tue, 12 Nov 2019 13:48:41 +0700 Subject: [PATCH 1/2] refactor(v2): simplify blog truncate function --- packages/docusaurus-plugin-content-blog/src/blogUtils.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index 1a7ca4df3c71..83c2609a8d7d 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -7,11 +7,7 @@ import {parse, normalizeUrl} from '@docusaurus/utils'; import {LoadContext} from '@docusaurus/types'; export function truncate(fileString: string, truncateMarker: RegExp | string) { - const truncated = - typeof truncateMarker === 'string' - ? fileString.includes(truncateMarker) - : truncateMarker.test(fileString); - return truncated ? fileString.split(truncateMarker)[0] : fileString; + return fileString.split(truncateMarker, 1).shift() || fileString; } // YYYY-MM-DD-{name}.mdx? From 1cb49391f51968b68857066702da54a1b414765c Mon Sep 17 00:00:00 2001 From: Endi Date: Tue, 12 Nov 2019 16:15:25 +0700 Subject: [PATCH 2/2] Update packages/docusaurus-plugin-content-blog/src/blogUtils.ts Co-Authored-By: Alexey Pyltsyn --- packages/docusaurus-plugin-content-blog/src/blogUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index 83c2609a8d7d..870f7f007e57 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -7,7 +7,7 @@ import {parse, normalizeUrl} from '@docusaurus/utils'; import {LoadContext} from '@docusaurus/types'; export function truncate(fileString: string, truncateMarker: RegExp | string) { - return fileString.split(truncateMarker, 1).shift() || fileString; + return fileString.split(truncateMarker, 1).shift()!; } // YYYY-MM-DD-{name}.mdx?