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