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

Apply a function approach to the route-error component. #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 12 additions & 16 deletions app/components/route-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@ import Ember from 'ember';
import markdownFiles from 'ember-fr-markdown-file/markdownFiles';

const { computed } = Ember;
const excludedPages = ['intro'];

export default Ember.Component.extend({
_parseObj(obj, dir) {
let prefix = dir || '';
let result = [];
let that = this;
for (let prop in obj) {
let value = obj[prop];
if (typeof value === 'object') {
result.push(that._parseObj(value, prop));
} else {
if (prop !== 'intro') {
result.push(`${prefix}/${prop}`.replace(/^\//, ''));
}
}
}
return result;
_parsePages(obj, prefix) {
return Object.keys(obj).map(key => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect we should provide a helper for this, having this as docs feels brittle + tech debty thoughts?

const value = obj[key];
if (typeof value === 'object') {
return this._parsePages(value, key);
}
return prefix ? `${prefix}/${key}` : key;
})
.reject(p => excludedPages.includes(p))
.reverse();
},
availablePages: computed(function() {
return [].concat.apply([], this._parseObj(markdownFiles));
return [].concat.apply([], this._parsePages(markdownFiles));
})
});