diff --git a/src/main.js b/src/main.js
index 25a2b64..10063f9 100644
--- a/src/main.js
+++ b/src/main.js
@@ -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';
diff --git a/src/pages/archive-page.jsx b/src/pages/archive-page.jsx
index fff76e8..9d14fe2 100644
--- a/src/pages/archive-page.jsx
+++ b/src/pages/archive-page.jsx
@@ -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,
diff --git a/src/routing.js b/src/routing.js
index 548c79d..f7784e2 100644
--- a/src/routing.js
+++ b/src/routing.js
@@ -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);
}
}
diff --git a/src/widgets/side-nav.jsx b/src/widgets/side-nav.jsx
index 00e2bb9..2a51da8 100644
--- a/src/widgets/side-nav.jsx
+++ b/src/widgets/side-nav.jsx
@@ -139,7 +139,7 @@ class SideNavSync extends PureComponent {
})
}
- )
+ );
}
renderCategory(category, i) {
@@ -159,10 +159,30 @@ class SideNavSync extends PureComponent {
return (
{name}
+ {this.renderSubcategories(category)}
);
}
+ 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 (
+
+ {
+ subcategories.map((subcategory, i) => {
+ return this.renderCategory(subcategory, i);
+ })
+ }
+
+ );
+ }
+
renderArchive() {
let { archive } = this.props;
if (!archive) {
diff --git a/src/wordpress-data-source.js b/src/wordpress-data-source.js
deleted file mode 100644
index 9ad6759..0000000
--- a/src/wordpress-data-source.js
+++ /dev/null
@@ -1,2546 +0,0 @@
-var EventEmitter = require('relaks-event-emitter');
-var GenericEvent = EventEmitter.GenericEvent;
-
-var defaultOptions = {
- baseURL: '',
- permalinks: true,
- refreshInterval: 0,
- authorizationKeyword: 'Token',
- abbreviatedFolderContents: false,
- fetchFunc: null,
-};
-
-function RelaksWordpressDataSource(options) {
- EventEmitter.call(this);
- this.active = false;
- this.activationPromise = null;
- this.queries = [];
- this.authentications = [];
- this.authorizations = [];
- this.options = {};
- for (var name in defaultOptions) {
- if (options && options[name] !== undefined) {
- this.options[name] = options[name];
- } else {
- this.options[name] = defaultOptions[name];
- }
- }
-}
-
-var prototype = RelaksWordpressDataSource.prototype = Object.create(EventEmitter.prototype)
-
-/**
- * Activate the component
- */
-prototype.activate = function() {
- if (!this.active) {
- this.active = true;
- if (this.activationPromise) {
- var resolve = this.activationPromise.resolve;
- this.activationPromise = null;
- resolve();
- }
- this.startExpirationCheck();
- this.checkExpiration();
- }
-};
-
-/**
- * Activate the component
- */
-prototype.deactivate = function() {
- if (this.active) {
- this.stopExpirationCheck();
- this.active = false;
- }
-};
-
-/**
- * Add baseURL to relative URL
- *
- * @param {String} url
- *
- * @return {String}
- */
-prototype.resolveURL = function(url) {
- if (typeof(url) !== 'string') {
- return url;
- }
- var baseURL = this.options.baseURL;
- if (baseURL && !/^https?:/.test(url)) {
- if (!/^https?:/.test(baseURL)) {
- if (typeof(location) === 'object') {
- baseURL = location.protocol + '//' + location.host + baseURL;
- } else {
- if (process.env.NODE_ENV !== 'production') {
- console.warn('Base URL is not absolute');
- }
- }
- }
-
- var permalinks = this.options.permalinks;
- if (permalinks) {
- url = removeTrailingSlash(baseURL) + addLeadingSlash(url);
- } else {
- url = baseURL + '?rest_route=' + encodeURI(url);
- }
- }
- return addTrailingSlash(url);
-};
-
-/**
- * Resolve a list of URLs
- *
- * @param {Array} urls
- *
- * @return {Array}
- */
-prototype.resolveURLs = function(urls) {
- var _this = this;
- return urls.map(function(url) {
- return _this.resolveURL(url);
- });
-};
-
-/**
- * Trigger a 'change' event unless changed is false
- *
- * @param {Boolean} changed
- *
- * @return {Boolean}
- */
-prototype.notifyChanges = function(changed) {
- if (changed === false) {
- return false;
- }
- this.triggerEvent(new RelaksWordpressDataSourceEvent('change', this));
- return true;
-};
-
-/**
- * Fetch one object at the URL.
- *
- * @param {String} url
- * @param {Number|String|undefined} id
- * @param {Object|undefined} options
- *
- * @return {Promise