mirror of
https://github.com/trambarhq/relaks-wordpress-example.git
synced 2025-09-24 22:41:31 +02:00
Added subcategories (issue #22).
Moved WordPress data source to own repo (issue #16).
This commit is contained in:
@@ -3,7 +3,7 @@ import { createElement } from 'react';
|
||||
import { hydrate, render } from 'react-dom';
|
||||
import { FrontEnd } from 'front-end';
|
||||
import { Route, routes } from 'routing';
|
||||
import WordpressDataSource from 'wordpress-data-source';
|
||||
import WordpressDataSource from 'relaks-wordpress-data-source';
|
||||
import RouteManager from 'relaks-route-manager';
|
||||
import { harvest } from 'relaks-harvest';
|
||||
import Relaks, { plant } from 'relaks';
|
||||
|
@@ -13,7 +13,7 @@ class ArchivePage extends AsyncComponent {
|
||||
async renderAsync(meanwhile) {
|
||||
let { wp, route } = this.props;
|
||||
let { date } = route.params;
|
||||
let month = Moment(`${date.year}-${date.month}`);
|
||||
let month = Moment(`${date.year}-${_.padStart(date.month, 2, '0')}`);
|
||||
let props = {
|
||||
route,
|
||||
month,
|
||||
|
@@ -26,7 +26,7 @@ class Route {
|
||||
|
||||
getArchiveURL(date) {
|
||||
let { year, month } = date;
|
||||
return this.composeURL({ path: `/date/${year}/${month}/` });
|
||||
return this.composeURL({ path: `/date/${year}/${_.padStart(month, 2, '0')}/` });
|
||||
}
|
||||
|
||||
getObjectURL(object) {
|
||||
@@ -39,8 +39,6 @@ class Route {
|
||||
return this.composeURL({ path });
|
||||
}
|
||||
|
||||
|
||||
|
||||
composeURL(urlParts) {
|
||||
let context = _.clone(this.routeManager.context);
|
||||
this.routeManager.rewrite('to', urlParts, context);
|
||||
@@ -57,8 +55,7 @@ class Route {
|
||||
// get the site URL and see what the page's URL would be if it
|
||||
// were on WordPress itself
|
||||
let siteURL = await this.getSiteURL();
|
||||
let link = siteURL + path;
|
||||
console.log(link);
|
||||
let link = _.trimEnd(siteURL + path, '/') + '/';
|
||||
|
||||
// see if it's a search
|
||||
let search = query.s;
|
||||
@@ -188,7 +185,7 @@ function findMatchingSlugs(objects, link) {
|
||||
let matches = [];
|
||||
for (let object of objects) {
|
||||
let objectLink = _.trimEnd(object.link, '/') + '/';
|
||||
if (_.startsWith(objectLink, link)) {
|
||||
if (_.startsWith(link, objectLink)) {
|
||||
matches.push(object);
|
||||
}
|
||||
}
|
||||
|
@@ -139,7 +139,7 @@ class SideNavSync extends PureComponent {
|
||||
})
|
||||
}
|
||||
</ul>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
renderCategory(category, i) {
|
||||
@@ -159,10 +159,30 @@ class SideNavSync extends PureComponent {
|
||||
return (
|
||||
<li key={i}>
|
||||
<a className={className} href={url} title={description}>{name}</a>
|
||||
{this.renderSubcategories(category)}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
renderSubcategories(category) {
|
||||
let { categories } = this.props;
|
||||
let subcategories = _.filter(categories, { parent: category.id });
|
||||
subcategories = _.filter(subcategories, 'count');
|
||||
subcategories = _.orderBy(subcategories, [ 'count', 'name' ], [ 'desc', 'asc' ]);
|
||||
if (!subcategories.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<ul className="subcategories">
|
||||
{
|
||||
subcategories.map((subcategory, i) => {
|
||||
return this.renderCategory(subcategory, i);
|
||||
})
|
||||
}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
renderArchive() {
|
||||
let { archive } = this.props;
|
||||
if (!archive) {
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user