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:
parent
527d201ed5
commit
c765cb0b76
@ -1,6 +1,5 @@
|
|||||||
import trimStart from 'lodash/trimStart';
|
import trimStart from 'lodash/trimStart';
|
||||||
import semaphore from "semaphore";
|
import semaphore from "semaphore";
|
||||||
import { fileExtension } from 'Lib/pathHelper'
|
|
||||||
import AuthenticationPage from "./AuthenticationPage";
|
import AuthenticationPage from "./AuthenticationPage";
|
||||||
import API from "./API";
|
import API from "./API";
|
||||||
|
|
||||||
@ -53,7 +52,7 @@ export default class GitHub {
|
|||||||
|
|
||||||
entriesByFolder(collection, extension) {
|
entriesByFolder(collection, extension) {
|
||||||
return this.api.listFiles(collection.get("folder"))
|
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);
|
.then(this.fetchFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { remove, attempt, isError } from 'lodash';
|
import { remove, attempt, isError } from 'lodash';
|
||||||
import uuid from 'uuid/v4';
|
import uuid from 'uuid/v4';
|
||||||
import { fileExtension } from 'Lib/pathHelper'
|
|
||||||
import AuthenticationPage from './AuthenticationPage';
|
import AuthenticationPage from './AuthenticationPage';
|
||||||
|
|
||||||
window.repoFiles = window.repoFiles || {};
|
window.repoFiles = window.repoFiles || {};
|
||||||
@ -45,7 +44,7 @@ export default class TestRepo {
|
|||||||
const folder = collection.get('folder');
|
const folder = collection.get('folder');
|
||||||
if (folder) {
|
if (folder) {
|
||||||
for (const path in window.repoFiles[folder]) {
|
for (const path in window.repoFiles[folder]) {
|
||||||
if (fileExtension(path) !== extension) {
|
if (!path.endsWith('.' + extension)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { OrderedMap, fromJS } from 'immutable';
|
import { OrderedMap, fromJS } from 'immutable';
|
||||||
import { has, get } from 'lodash';
|
import { has, get, escapeRegExp } from 'lodash';
|
||||||
import consoleError from 'Lib/consoleError';
|
import consoleError from 'Lib/consoleError';
|
||||||
import { CONFIG_SUCCESS } from 'Actions/config';
|
import { CONFIG_SUCCESS } from 'Actions/config';
|
||||||
import { FILES, FOLDER } from 'Constants/collectionTypes';
|
import { FILES, FOLDER } from 'Constants/collectionTypes';
|
||||||
@ -48,7 +48,7 @@ function validateCollection(configCollection) {
|
|||||||
const selectors = {
|
const selectors = {
|
||||||
[FOLDER]: {
|
[FOLDER]: {
|
||||||
entryExtension(collection) {
|
entryExtension(collection) {
|
||||||
return collection.get('extension') || formatToExtension(collection.get('format') || 'frontmatter');
|
return (collection.get('extension') || formatToExtension(collection.get('format') || 'frontmatter')).replace(/^\./, '');
|
||||||
},
|
},
|
||||||
fields(collection) {
|
fields(collection) {
|
||||||
return collection.get('fields');
|
return collection.get('fields');
|
||||||
@ -57,7 +57,7 @@ const selectors = {
|
|||||||
return `${ collection.get('folder').replace(/\/$/, '') }/${ slug }.${ this.entryExtension(collection) }`;
|
return `${ collection.get('folder').replace(/\/$/, '') }/${ slug }.${ this.entryExtension(collection) }`;
|
||||||
},
|
},
|
||||||
entrySlug(collection, path) {
|
entrySlug(collection, path) {
|
||||||
return path.split('/').pop().replace(/\.[^\.]+$/, '');
|
return path.split('/').pop().replace(new RegExp(`\.${ escapeRegExp(this.entryExtension(collection)) }$`), '');
|
||||||
},
|
},
|
||||||
listMethod() {
|
listMethod() {
|
||||||
return 'entriesByFolder';
|
return 'entriesByFolder';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user