Support extensions with multiple parts (i.e. en.md) (#1123)

* Support extensions with multiple parts (i.e. `en.md`)

* Strip entire extension from slug, not just last extension.

* Clean leading periods from extensions.
This commit is contained in:
Caleb 2018-02-27 15:23:20 -07:00 committed by Shawn Erquhart
parent 527d201ed5
commit c765cb0b76
3 changed files with 5 additions and 7 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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';
@ -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');
@ -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';