From 8e88905c48483012e1a2355efbbbd502863ef1f1 Mon Sep 17 00:00:00 2001
From: ppoffice
Date: Mon, 23 Dec 2019 17:11:22 -0500
Subject: [PATCH] refactor(layout): all layout files to jsx
---
layout/archive.ejs | 56 ------------------------
layout/archive.jsx | 84 ++++++++++++++++++++++++++++++++++++
layout/categories.ejs | 30 -------------
layout/categories.jsx | 14 ++++++
layout/category.ejs | 14 ------
layout/category.jsx | 30 +++++++++++++
layout/common/article.jsx | 2 +-
layout/common/head.jsx | 4 +-
layout/common/navbar.jsx | 2 +-
layout/common/search.jsx | 22 ++++++++++
layout/index.ejs | 6 ---
layout/index.jsx | 26 +++++++++++
layout/layout.ejs | 35 ---------------
layout/layout.jsx | 49 +++++++++++++++++++++
layout/page.ejs | 1 -
layout/page.jsx | 15 +++++++
layout/post.ejs | 1 -
layout/post.jsx | 15 +++++++
layout/search/baidu.jsx | 8 ++--
layout/search/google-cse.jsx | 8 ++--
layout/search/insight.jsx | 16 ++++---
layout/tag.ejs | 11 -----
layout/tag.jsx | 27 ++++++++++++
layout/tags.ejs | 19 --------
layout/tags.jsx | 14 ++++++
25 files changed, 320 insertions(+), 189 deletions(-)
delete mode 100644 layout/archive.ejs
create mode 100644 layout/archive.jsx
delete mode 100644 layout/categories.ejs
create mode 100644 layout/categories.jsx
delete mode 100644 layout/category.ejs
create mode 100644 layout/category.jsx
create mode 100644 layout/common/search.jsx
delete mode 100644 layout/index.ejs
create mode 100644 layout/index.jsx
delete mode 100644 layout/layout.ejs
create mode 100644 layout/layout.jsx
delete mode 100644 layout/page.ejs
create mode 100644 layout/page.jsx
delete mode 100644 layout/post.ejs
create mode 100644 layout/post.jsx
delete mode 100644 layout/tag.ejs
create mode 100644 layout/tag.jsx
delete mode 100644 layout/tags.ejs
create mode 100644 layout/tags.jsx
diff --git a/layout/archive.ejs b/layout/archive.ejs
deleted file mode 100644
index ace6b41..0000000
--- a/layout/archive.ejs
+++ /dev/null
@@ -1,56 +0,0 @@
-<% function buildArchive(posts, year, month = null) {
- const time = moment([page.year, page.month ? page.month - 1 : null].filter(i => i !== null)); %>
-
-<% }
-if (!page.year) {
- let years = {};
- page.posts.each(p => years[p.date.year()] = null);
- for (let year of Object.keys(years).sort((a, b) => b - a)) {
- let posts = page.posts.filter(p => p.date.year() == year); %>
- <%- buildArchive(posts, year, null) %>
- <% }
-} else { %>
-<%- buildArchive(page.posts, page.year, page.month) %>
-<% } %>
-<% if (page.total > 1) { %>
- <%- _partial('common/paginator') %>
-<% } %>
\ No newline at end of file
diff --git a/layout/archive.jsx b/layout/archive.jsx
new file mode 100644
index 0000000..ddca928
--- /dev/null
+++ b/layout/archive.jsx
@@ -0,0 +1,84 @@
+'use strict';
+
+const moment = require('moment');
+const { Component, Fragment } = require('inferno');
+const Paginator = require('./misc/paginator');
+
+module.exports = class extends Component {
+ render() {
+ const { page } = this.props;
+ // TODO
+ const helper = {};
+ const config = {};
+ const { url_for, __, has_thumbnail, get_thumbnail, date_xml, date } = helper;
+
+ const language = page.lang || page.language || config.language;
+
+ function renderArticleList(posts, year, month = null) {
+ const time = moment([page.year, page.month ? page.month - 1 : null].filter(i => i !== null));
+
+ return ;
+ }
+
+ let articleList;
+ if (!page.year) {
+ const years = {};
+ page.posts.each(p => years[p.date.year()] = null);
+ articleList = Object.keys(years).sort((a, b) => b - a).map(year => {
+ let posts = page.posts.filter(p => p.date.year() == year);
+ return renderArticleList(posts, year, null);
+ });
+ } else {
+ articleList = renderArticleList(page.posts, page.year, page.month);
+ }
+
+ return
+ {articleList}
+ {page.total > 1 ? : null}
+ ;
+ }
+}
\ No newline at end of file
diff --git a/layout/categories.ejs b/layout/categories.ejs
deleted file mode 100644
index 09655f8..0000000
--- a/layout/categories.ejs
+++ /dev/null
@@ -1,30 +0,0 @@
-<% function build_list(categories) {
- return categories.map(category => {
- let result = `
-
-
- ${category.name}
-
-
- ${category.count}
-
- `;
- if (category.hasOwnProperty('children')) {
- result += '' + build_list(category.children) + '
';
- }
- return result + '';
- }).join('');
-}
-%>
-
\ No newline at end of file
diff --git a/layout/categories.jsx b/layout/categories.jsx
new file mode 100644
index 0000000..04ce414
--- /dev/null
+++ b/layout/categories.jsx
@@ -0,0 +1,14 @@
+'use strict';
+
+const { Component } = require('inferno');
+const Categories = require('./widget/categories');
+
+module.exports = class extends Component {
+ render() {
+ const { site, page } = this.props;
+ // TODO
+ const helper = {};
+
+ return ;
+ }
+}
\ No newline at end of file
diff --git a/layout/category.ejs b/layout/category.ejs
deleted file mode 100644
index 3822544..0000000
--- a/layout/category.ejs
+++ /dev/null
@@ -1,14 +0,0 @@
-
-<%- _partial('index', { page }) %>
\ No newline at end of file
diff --git a/layout/category.jsx b/layout/category.jsx
new file mode 100644
index 0000000..65bd4b3
--- /dev/null
+++ b/layout/category.jsx
@@ -0,0 +1,30 @@
+'use strict';
+
+const { Component, Fragment } = require('inferno');
+const Index = require('./index');
+
+module.exports = class extends Component {
+ render() {
+ const { page } = this.props;
+ // TODO
+ const helper = {};
+ const { url_for, _p } = helper;
+
+ return
+
+
+ ;
+ }
+}
\ No newline at end of file
diff --git a/layout/common/article.jsx b/layout/common/article.jsx
index ae0efb5..d73d040 100644
--- a/layout/common/article.jsx
+++ b/layout/common/article.jsx
@@ -7,7 +7,7 @@ const Donates = require('./donates');
const Comment = require('./comment');
/**
- * Get the word count of a paragraph.
+ * Get the word count of text.
*/
function getWordCount(content) {
content = content.replace(/<\/?[a-z][^>]*>/gi, '');
diff --git a/layout/common/head.jsx b/layout/common/head.jsx
index ba4d08c..bd23809 100644
--- a/layout/common/head.jsx
+++ b/layout/common/head.jsx
@@ -21,6 +21,8 @@ module.exports = class extends Component {
highlight
} = config;
+ const language = page.lang || page.language || config.language;
+
let hlTheme, images;
if (highlight && highlight.enable === false) {
hlTheme = null;
@@ -64,7 +66,7 @@ module.exports = class extends Component {
url={url}
images={page.photos || images}
siteName={config.title}
- language={page.lang || page.language || config.language}
+ language={language}
twitterId={open_graph.twitter}
googlePlus={open_graph.google_plus}
facebookAdmins={open_graph.fb_admins}
diff --git a/layout/common/navbar.jsx b/layout/common/navbar.jsx
index 0eb70f4..90c63b4 100644
--- a/layout/common/navbar.jsx
+++ b/layout/common/navbar.jsx
@@ -66,7 +66,7 @@ class Navbar extends Component {
}
module.exports = cacheComponent(Navbar, 'common.navbar', props => {
- const { config, helper, page } = this.props;
+ const { config, helper, page } = props;
const { url_for, _p, __ } = helper;
const { logo, title, navbar, widgets, search } = config;
diff --git a/layout/common/search.jsx b/layout/common/search.jsx
new file mode 100644
index 0000000..e719589
--- /dev/null
+++ b/layout/common/search.jsx
@@ -0,0 +1,22 @@
+'use strict';
+
+const logger = require('hexo-log');
+const { Component } = require('inferno');
+
+module.exports = class extends Component {
+ render() {
+ const { config, helper } = this.props;
+ const { search } = config;
+ if (!search || typeof search.type !== 'string') {
+ return null;
+ }
+
+ try {
+ const Search = require('../search/' + search.type);
+ return ;
+ } catch (e) {
+ logger.warn(`Icarus cannot load search "${search.type}"`);
+ return null;
+ }
+ }
+};
diff --git a/layout/index.ejs b/layout/index.ejs
deleted file mode 100644
index 4305b6c..0000000
--- a/layout/index.ejs
+++ /dev/null
@@ -1,6 +0,0 @@
-<% page.posts.each(function(post){ %>
- <%- _partial('common/article', { post, index: true }) %>
-<% }); %>
-<% if (page.total > 1) { %>
- <%- _partial('common/paginator') %>
-<% } %>
\ No newline at end of file
diff --git a/layout/index.jsx b/layout/index.jsx
new file mode 100644
index 0000000..3ff2676
--- /dev/null
+++ b/layout/index.jsx
@@ -0,0 +1,26 @@
+'use strict';
+
+const { Component, Fragment } = require('inferno');
+const Article = require('./common/article');
+const Paginator = require('./misc/paginator');
+
+module.exports = class extends Component {
+ render() {
+ const { page } = this.props;
+ // TODO
+ const helper = {};
+ const config = {};
+
+ return
+ {page.posts.each(post => )}
+ {page.total > 1 ? : null}
+ ;
+ }
+}
\ No newline at end of file
diff --git a/layout/layout.ejs b/layout/layout.ejs
deleted file mode 100644
index 7370c98..0000000
--- a/layout/layout.ejs
+++ /dev/null
@@ -1,35 +0,0 @@
-
->
-
- <%- _partial('common/head') %>
-
-
- <%- _partial('common/navbar') %>
- <% function main_column_class() {
- switch (column_count()) {
- case 1:
- return 'is-12';
- case 2:
- return 'is-8-tablet is-8-desktop is-8-widescreen';
- case 3:
- return 'is-8-tablet is-8-desktop is-6-widescreen'
- }
- return '';
- } %>
-
-
-
-
<%- body %>
- <%- _partial('common/widget', { position: 'left' }) %>
- <%- _partial('common/widget', { position: 'right' }) %>
-
-
-
- <%- _partial('common/footer') %>
- <%- _partial('common/scripts') %>
-
- <% if (has_config('search.type')) { %>
- <%- _partial('search/' + get_config('search.type')) %>
- <% } %>
-
-
\ No newline at end of file
diff --git a/layout/layout.jsx b/layout/layout.jsx
new file mode 100644
index 0000000..147d9cf
--- /dev/null
+++ b/layout/layout.jsx
@@ -0,0 +1,49 @@
+'use strict';
+
+const { Component } = require('inferno');
+const Head = require('./common/head');
+const Navbar = require('./common/navbar');
+const Widgets = require('./common/widgets');
+const Footer = require('./common/footer');
+const Scripts = require('./common/scripts');
+const Search = require('./common/search');
+
+module.exports = class extends Component {
+ render() {
+ const { env, site, page, body } = this.props;
+ // TODO
+ const helper = {};
+ const config = {};
+
+ const language = page.lang || page.language || config.language;
+ const columnCount = Widgets.getColumnCount(config.widgets);
+
+ return
+
+
+
+
+
+
+
+
+
+
+ ;
+ }
+}
\ No newline at end of file
diff --git a/layout/page.ejs b/layout/page.ejs
deleted file mode 100644
index 8161cf1..0000000
--- a/layout/page.ejs
+++ /dev/null
@@ -1 +0,0 @@
-<%- _partial('common/article', {post: page, index: false}) %>
\ No newline at end of file
diff --git a/layout/page.jsx b/layout/page.jsx
new file mode 100644
index 0000000..a0d4e84
--- /dev/null
+++ b/layout/page.jsx
@@ -0,0 +1,15 @@
+'use strict';
+
+const { Component } = require('inferno');
+const Article = require('./common/article');
+
+module.exports = class extends Component {
+ render() {
+ const { page } = this.props;
+ // TODO
+ const helper = {};
+ const config = {};
+
+ return ;
+ }
+}
\ No newline at end of file
diff --git a/layout/post.ejs b/layout/post.ejs
deleted file mode 100644
index 8161cf1..0000000
--- a/layout/post.ejs
+++ /dev/null
@@ -1 +0,0 @@
-<%- _partial('common/article', {post: page, index: false}) %>
\ No newline at end of file
diff --git a/layout/post.jsx b/layout/post.jsx
new file mode 100644
index 0000000..a0d4e84
--- /dev/null
+++ b/layout/post.jsx
@@ -0,0 +1,15 @@
+'use strict';
+
+const { Component } = require('inferno');
+const Article = require('./common/article');
+
+module.exports = class extends Component {
+ render() {
+ const { page } = this.props;
+ // TODO
+ const helper = {};
+ const config = {};
+
+ return ;
+ }
+}
\ No newline at end of file
diff --git a/layout/search/baidu.jsx b/layout/search/baidu.jsx
index 90c246b..fb00e2b 100644
--- a/layout/search/baidu.jsx
+++ b/layout/search/baidu.jsx
@@ -42,9 +42,11 @@ class Baidu extends Component {
}
module.exports = cacheComponent(Baidu, 'search.baidu', props => {
+ const { config, helper } = props;
+
return {
- url: props.config.url,
- hint: props.__('search.hint'),
- url_for: props.url_for
+ url: config.url,
+ hint: helper.__('search.hint'),
+ url_for: helper.url_for
};
});
diff --git a/layout/search/google-cse.jsx b/layout/search/google-cse.jsx
index c73569d..8adc539 100644
--- a/layout/search/google-cse.jsx
+++ b/layout/search/google-cse.jsx
@@ -80,9 +80,11 @@ class Google extends Component {
}
module.exports = cacheComponent(Google, 'search.google', props => {
+ const { helper, search } = props;
+
return {
- cx: props.cx,
- hint: props.__('search.hint'),
- url_for: props.url_for
+ cx: search.cx,
+ hint: helper.__('search.hint'),
+ url_for: helper.url_for
};
});
diff --git a/layout/search/insight.jsx b/layout/search/insight.jsx
index 893782f..454f10c 100644
--- a/layout/search/insight.jsx
+++ b/layout/search/insight.jsx
@@ -42,15 +42,17 @@ class Insight extends Component {
}
module.exports = cacheComponent(Insight, 'search.insight', props => {
+ const { helper } = props;
+
return {
- hint: props.__('search.hint'),
+ hint: helper.__('search.hint'),
translation: {
- posts: props.__('insight.posts'),
- pages: props.__('insight.pages'),
- categories: props.__('insight.categories'),
- tags: props.__('insight.tags'),
- untitled: props.__('insight.untitled')
+ posts: helper.__('insight.posts'),
+ pages: helper.__('insight.pages'),
+ categories: helper.__('insight.categories'),
+ tags: helper.__('insight.tags'),
+ untitled: helper.__('insight.untitled')
},
- url_for: props.url_for
+ url_for: helper.url_for
};
});
diff --git a/layout/tag.ejs b/layout/tag.ejs
deleted file mode 100644
index b2b2d04..0000000
--- a/layout/tag.ejs
+++ /dev/null
@@ -1,11 +0,0 @@
-
-<%- _partial('index', { page }) %>
\ No newline at end of file
diff --git a/layout/tag.jsx b/layout/tag.jsx
new file mode 100644
index 0000000..08e92b6
--- /dev/null
+++ b/layout/tag.jsx
@@ -0,0 +1,27 @@
+'use strict';
+
+const { Component, Fragment } = require('inferno');
+const Index = require('./index');
+
+module.exports = class extends Component {
+ render() {
+ const { page } = this.props;
+ // TODO
+ const helper = {};
+ const { url_for, _p } = helper;
+
+ return
+
+
+ ;
+ }
+}
\ No newline at end of file
diff --git a/layout/tags.ejs b/layout/tags.ejs
deleted file mode 100644
index ae9f6c5..0000000
--- a/layout/tags.ejs
+++ /dev/null
@@ -1,19 +0,0 @@
-
\ No newline at end of file
diff --git a/layout/tags.jsx b/layout/tags.jsx
new file mode 100644
index 0000000..4d99d75
--- /dev/null
+++ b/layout/tags.jsx
@@ -0,0 +1,14 @@
+'use strict';
+
+const { Component } = require('inferno');
+const Tags = require('./widget/tags');
+
+module.exports = class extends Component {
+ render() {
+ const { site } = this.props;
+ // TODO
+ const helper = {};
+
+ return ;
+ }
+}
\ No newline at end of file