From f6293b0c88168cbfe635f414f8f178bef1033590 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 9 Jan 2018 14:10:04 -0700 Subject: [PATCH 1/3] Support extensions with multiple parts (i.e. `en.md`) --- src/backends/github/implementation.js | 3 +-- src/backends/test-repo/implementation.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/backends/github/implementation.js b/src/backends/github/implementation.js index f357b6c82ff9..19947dd35865 100644 --- a/src/backends/github/implementation.js +++ b/src/backends/github/implementation.js @@ -1,6 +1,5 @@ import trimStart from 'lodash/trimStart'; import semaphore from "semaphore"; -import { fileExtension } from 'Lib/pathHelper' import AuthenticationPage from "./AuthenticationPage"; import API from "./API"; @@ -53,7 +52,7 @@ export default class GitHub { entriesByFolder(collection, extension) { return this.api.listFiles(collection.get("folder")) - .then(files => files.filter(file => fileExtension(file.name) === extension)) + .then(files => files.filter(file => file.name.endsWith('.' + extension))) .then(this.fetchFiles); } diff --git a/src/backends/test-repo/implementation.js b/src/backends/test-repo/implementation.js index 55a723ded3ef..40d9b1238a53 100644 --- a/src/backends/test-repo/implementation.js +++ b/src/backends/test-repo/implementation.js @@ -1,6 +1,5 @@ import { remove, attempt, isError } from 'lodash'; import uuid from 'uuid/v4'; -import { fileExtension } from 'Lib/pathHelper' import AuthenticationPage from './AuthenticationPage'; window.repoFiles = window.repoFiles || {}; @@ -45,7 +44,7 @@ export default class TestRepo { const folder = collection.get('folder'); if (folder) { for (const path in window.repoFiles[folder]) { - if (fileExtension(path) !== extension) { + if (!path.endsWith('.' + extension)) { continue; } From e2f8d492485bc8bd77a620e9e057f842499ffdd4 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 20 Feb 2018 17:36:42 -0700 Subject: [PATCH 2/3] Strip entire extension from slug, not just last extension. --- src/reducers/collections.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/reducers/collections.js b/src/reducers/collections.js index bddf78a713e0..b012f63ff941 100644 --- a/src/reducers/collections.js +++ b/src/reducers/collections.js @@ -1,5 +1,5 @@ import { OrderedMap, fromJS } from 'immutable'; -import { has, get } from 'lodash'; +import { has, get, escapeRegExp } from 'lodash'; import consoleError from 'Lib/consoleError'; import { CONFIG_SUCCESS } from 'Actions/config'; import { FILES, FOLDER } from 'Constants/collectionTypes'; @@ -57,7 +57,7 @@ const selectors = { return `${ collection.get('folder').replace(/\/$/, '') }/${ slug }.${ this.entryExtension(collection) }`; }, entrySlug(collection, path) { - return path.split('/').pop().replace(/\.[^\.]+$/, ''); + return path.split('/').pop().replace(new RegExp(`\.${ escapeRegExp(this.entryExtension(collection)) }$`), ''); }, listMethod() { return 'entriesByFolder'; From e2729eb93f3d6dc12d1b918bfec4922331382a46 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 27 Feb 2018 09:49:57 -0700 Subject: [PATCH 3/3] Clean leading periods from extensions. --- src/reducers/collections.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reducers/collections.js b/src/reducers/collections.js index b012f63ff941..9f798baf9a37 100644 --- a/src/reducers/collections.js +++ b/src/reducers/collections.js @@ -48,7 +48,7 @@ function validateCollection(configCollection) { const selectors = { [FOLDER]: { entryExtension(collection) { - return collection.get('extension') || formatToExtension(collection.get('format') || 'frontmatter'); + return (collection.get('extension') || formatToExtension(collection.get('format') || 'frontmatter')).replace(/^\./, ''); }, fields(collection) { return collection.get('fields');