Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/backends/github/implementation.js
Original file line number Diff line number Diff line change
@@ -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";

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

Expand Down
3 changes: 1 addition & 2 deletions src/backends/test-repo/implementation.js
Original file line number Diff line number Diff line change
@@ -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 || {};
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/reducers/collections.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
Expand All @@ -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';
Expand Down