mirror of
https://github.com/trambarhq/relaks-wordpress-example.git
synced 2025-09-24 22:41:31 +02:00
Fixed page link matching (issue #30).
Removed unnecessary show() calls.
This commit is contained in:
@@ -15,7 +15,6 @@ class ArchivePage extends AsyncComponent {
|
||||
let { date } = route.params;
|
||||
let month = Moment(`${date.year}-${_.padStart(date.month, 2, '0')}`);
|
||||
let props = { route, month };
|
||||
meanwhile.show(<ArchivePageSync {...props} />);
|
||||
let after = month.toISOString();
|
||||
let before = month.clone().endOf('month').toISOString();
|
||||
let url = `/wp/v2/posts/?after=${after}&before=${before}`;
|
||||
|
@@ -14,7 +14,6 @@ class CategoryPage extends AsyncComponent {
|
||||
let { wp, route } = this.props;
|
||||
let { categorySlug } = route.params;
|
||||
let props = { route };
|
||||
meanwhile.show(<CategoryPageSync {...props} />);
|
||||
props.category = await wp.fetchOne('/wp/v2/categories/', categorySlug);
|
||||
props.parentCategories = [];
|
||||
let parentID = props.category.parent;
|
||||
|
@@ -16,19 +16,19 @@ class PagePage extends AsyncComponent {
|
||||
let { wp, route } = this.props;
|
||||
let { pageSlug } = route.params;
|
||||
let props = { route };
|
||||
meanwhile.show(<PagePageSync {...props} />);
|
||||
props.page = await wp.fetchOne('/wp/v2/pages/', pageSlug);
|
||||
let pages = await wp.fetchList(`/wp/v2/pages/`, { minimum: '100%' });
|
||||
props.page = _.find(pages, { slug: pageSlug });
|
||||
props.parentPages = [];
|
||||
let parentID = props.page.parent;
|
||||
while (parentID) {
|
||||
let parentPage = await wp.fetchOne('/wp/v2/pages/', parentID);
|
||||
let parentPage = _.find(pages, { id: parentID });
|
||||
if (!parentPage) {
|
||||
break;
|
||||
}
|
||||
props.parentPages.push(parentPage);
|
||||
parentID = parentPage.parent;
|
||||
}
|
||||
props.childPages = await wp.fetchList(`/wp/v2/pages/?parent=${props.page.id}`);
|
||||
props.childPages = _.find(pages, { parent: props.page.id });
|
||||
return <PagePageSync {...props} />;
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@ class PostPage extends AsyncComponent {
|
||||
let { wp, route } = this.props;
|
||||
let { postSlug } = route.params;
|
||||
let props = { route };
|
||||
meanwhile.show(<PostPageSync {...props} />);
|
||||
props.post = await wp.fetchOne('/wp/v2/posts/', postSlug);
|
||||
meanwhile.show(<PostPageSync {...props} />);
|
||||
props.categories = await this.findCategoryChain(props.post.categories);
|
||||
|
@@ -13,7 +13,6 @@ class SearchPage extends AsyncComponent {
|
||||
let { wp, route } = this.props;
|
||||
let { search } = route.params;
|
||||
let props = { route };
|
||||
meanwhile.show(<SearchPageSync {...props} />);
|
||||
props.categories = await wp.fetchList('/wp/v2/categories/');
|
||||
if (search) {
|
||||
let s = encodeURIComponent(search);
|
||||
|
@@ -14,7 +14,6 @@ class TagPage extends AsyncComponent {
|
||||
let { wp, route } = this.props;
|
||||
let { tagSlug } = route.params;
|
||||
let props = { route };
|
||||
meanwhile.show(<TagPageSync {...props} />);
|
||||
props.tag = await wp.fetchOne('/wp/v2/tags/', tagSlug);
|
||||
meanwhile.show(<TagPageSync {...props} />);
|
||||
props.posts = await wp.fetchList(`/wp/v2/posts/?tags=${props.tag.id}`);
|
||||
|
@@ -11,7 +11,6 @@ class WelcomePage extends AsyncComponent {
|
||||
async renderAsync(meanwhile) {
|
||||
let { wp, route } = this.props;
|
||||
let props = { route };
|
||||
meanwhile.show(<WelcomePageSync {...props} />);
|
||||
props.posts = await wp.fetchList('/wp/v2/posts/');
|
||||
return <WelcomePageSync {...props} />;
|
||||
}
|
||||
|
@@ -60,6 +60,9 @@ class Route {
|
||||
// were on WordPress itself
|
||||
let siteURL = await this.getSiteURL();
|
||||
let link = _.trimEnd(siteURL + path, '/');
|
||||
let matchLink = (obj) => {
|
||||
return _.trimEnd(obj.link, '/') === link;
|
||||
};
|
||||
|
||||
// see if it's a search
|
||||
let search = query.s;
|
||||
@@ -89,21 +92,21 @@ class Route {
|
||||
|
||||
// see if it's pointing to a page
|
||||
let allPages = await this.dataSource.fetchList('/wp/v2/pages/', { minimum: '100%' });
|
||||
let page = _.find(allPages, { link });
|
||||
let page = _.find(allPages, matchLink);
|
||||
if (page) {
|
||||
return { pageType: 'page', pageSlug: page.slug, siteURL };
|
||||
}
|
||||
|
||||
// see if it's pointing to a category
|
||||
let allCategories = await this.dataSource.fetchList('/wp/v2/categories/', { minimum: '100%' });
|
||||
let category = _.find(allCategories, { link });
|
||||
let category = _.find(allCategories, matchLink);
|
||||
if (category) {
|
||||
return { pageType: 'category', categorySlug: category.slug, siteURL };
|
||||
}
|
||||
|
||||
// see if it's pointing to a tag
|
||||
let allTags = await this.dataSource.fetchList('/wp/v2/tags/', { minimum: '100%' });
|
||||
let tag = _.find(allTags, { link });
|
||||
let tag = _.find(allTags, matchLink);
|
||||
if (tag) {
|
||||
return { pageType: 'tag', tagSlug: tag.slug, siteURL };
|
||||
}
|
||||
@@ -137,7 +140,7 @@ class Route {
|
||||
|
||||
transformNode = (node) => {
|
||||
if (node.type === 'tag') {
|
||||
if (node.name === 'a') {
|
||||
if (node.name === 'a') {
|
||||
}
|
||||
} else if (node.type === 'text') {
|
||||
// trim off leading newline characters
|
||||
|
Reference in New Issue
Block a user