Skip to content

Commit

Permalink
Next (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexmoe committed Mar 19, 2023
2 parents b0f4d37 + 8a8797f commit 6e35382
Show file tree
Hide file tree
Showing 40 changed files with 4,380 additions and 846 deletions.
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

1 change: 1 addition & 0 deletions include/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refer from: <https://github.com/ppoffice/hexo-theme-icarus/tree/master/include>
102 changes: 102 additions & 0 deletions include/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* eslint no-process-exit: "off" */
const fs = require('fs');
const path = require('path');
const util = require('util');
const crypto = require('crypto');
const logger = require('hexo-log')();
const yaml = require('hexo-component-inferno/lib/util/yaml');
// const { Migrator } = require('hexo-component-inferno/lib/core/migrate');
// const { SchemaLoader } = require('hexo-component-inferno/lib/core/schema');
const { yellow } = require('./util/console');

function loadThemeConfig(hexo, cfgPaths) {
const configs = cfgPaths.map(cfgPath => fs.readFileSync(cfgPath))
.map(cfgPath => yaml.parse(cfgPath));
return Object.assign({}, ...configs, hexo.config.theme_config);
}

function generateThemeConfigFile(schema, cfgPath) {
const defaultValue = schema.getDefaultValue();
fs.writeFileSync(cfgPath, defaultValue.toYaml());
}

function hashConfigFile(cfgPath) {
const content = fs.readFileSync(cfgPath);
return crypto.createHash('md5').update(content).digest('hex');
}

function checkConfig(hexo) {
if (!process.argv.includes('--nexmoe-dont-check-config')) {
logger.info('[Nexmoe] Checking theme configurations');

const themeSiteCfg = path.join(hexo.base_dir, '_config.nexmoe.yml');
const themeDirCfg = path.join(hexo.theme_dir, '_config.yml');
const themeCfgPaths = [themeDirCfg, themeSiteCfg].filter(cfgPath => fs.existsSync(cfgPath));
const themeSiteCfgExample = themeSiteCfg + '.example';

// const schemaDir = path.join(hexo.theme_dir, 'include/schema/');
// const loader = SchemaLoader.load(require(path.join(schemaDir, 'config.json')), schemaDir);
// const schema = loader.getSchema('/config.json');

if (!process.argv.includes('--nexmoe-dont-generate-config')) {
if (!themeCfgPaths.length) {
logger.warn('None of the following configuration files is found:');
logger.warn(`- ${yellow(themeSiteCfg)}`);
logger.warn(`- ${yellow(themeDirCfg)}`);
logger.info('Generating theme configuration file...');
// generateThemeConfigFile(schema, themeSiteCfg);
fs.writeFileSync(themeSiteCfg, fs.readFileSync(path.join(hexo.theme_dir, 'source/_config.yml')))
themeCfgPaths.push(themeSiteCfg);
logger.info(`${yellow(themeSiteCfg)} created successfully.`);
logger.info('To skip configuration generation, use "--nexmoe-dont-generate-config".');
}
}

// let cfg = loadThemeConfig(hexo, themeCfgPaths);

// if (!process.argv.includes('--nexmoe-dont-upgrade-config')) {
// const migrator = new Migrator(require(path.join(hexo.theme_dir, 'include/migration/head')));
// if (cfg.version && migrator.isOudated(cfg.version)) {
// logger.warn(`Your theme configuration is outdated (${cfg.version} < ${migrator.getLatestVersion()}).`);
// logger.info('To skip the configuration upgrade, use "--nexmoe-dont-upgrade-config".');

// logger.info('Backing up theme configuration files...');
// for (const cfgPath of themeCfgPaths) {
// const backupPath = cfgPath + '.' + hashConfigFile(cfgPath);
// const relCfgPath = path.relative(hexo.base_dir, cfgPath);
// const relBackupPath = path.relative(hexo.base_dir, backupPath);
// fs.renameSync(cfgPath, backupPath);
// logger.info(`${yellow(relCfgPath)} => ${yellow(relBackupPath)}`);
// }

// logger.info('Upgrading theme configurations...');
// cfg = migrator.migrate(cfg);
// fs.writeFileSync(themeSiteCfg, yaml.stringify(cfg));
// logger.info(`Theme configurations are written to ${yellow(themeSiteCfg)}.`);

// generateThemeConfigFile(schema, themeSiteCfgExample);
// logger.info(`Example configurations is at ${yellow(themeSiteCfgExample)}.`);
// }
// }

// const validation = schema.validate(cfg);
// if (validation !== true) {
// logger.warn('Theme configurations failed one or more checks.');
// logger.warn('nexmoe may still run, but you will encounter unexcepted results.');
// logger.warn('Here is some information for you to correct the configuration file.');
// logger.warn(util.inspect(validation));
// }

}
}

module.exports = hexo => {
try {
checkConfig(hexo);
} catch (e) {
logger.error(e);
logger.error('Theme configuration checking failed.');
logger.info('You may use \'--nexmoe-dont-check-config\' to skip configuration checking.');
process.exit(-1);
}
};
34 changes: 34 additions & 0 deletions include/dependency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint no-process-exit: "off" */
const semver = require('semver');
const logger = require('hexo-log')();
const packageInfo = require('../package.json');
const { yellow, red, green } = require('./util/console');

module.exports = hexo => {
function checkDependency(name, reqVer) {
try {
require.resolve(name);
const version = require(name + '/package.json').version;
if (!semver.satisfies(version, reqVer)) {
logger.error(`Package ${yellow(name)}'s version (${yellow(version)}) does not satisfy the required version (${red(reqVer)}).`);
return false;
}
return true;
} catch (e) {
logger.error(`Package ${yellow(name)} is not installed.`);
}
return false;
}

logger.info('[Nexmoe] Checking package dependencies');
const dependencies = Object.assign({}, packageInfo.dependencies);
const missingDeps = Object.keys(dependencies)
.filter(name => !checkDependency(name, dependencies[name]));
if (missingDeps && missingDeps.length) {
logger.error('Please install the missing dependencies your Hexo site root directory:');
logger.error(green('npm install --save ' + missingDeps.map(name => `${name}@${dependencies[name]}`).join(' ')));
logger.error('or:');
logger.error(green('yarn add ' + missingDeps.map(name => `${name}@${dependencies[name]}`).join(' ')));
process.exit(-1);
}
};
17 changes: 17 additions & 0 deletions include/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const logger = require('hexo-log')();

module.exports = hexo => {
logger.info('=== Registering Hexo extensions ===');
require('hexo-component-inferno/lib/hexo/filter/locals')(hexo);
require('hexo-component-inferno/lib/hexo/generator/assets')(hexo);
require('hexo-component-inferno/lib/hexo/generator/insight')(hexo);
require('hexo-component-inferno/lib/hexo/generator/categories')(hexo);
require('hexo-component-inferno/lib/hexo/generator/category')(hexo);
require('hexo-component-inferno/lib/hexo/generator/manifest')(hexo);
require('hexo-component-inferno/lib/hexo/generator/tags')(hexo);
require('hexo-component-inferno/lib/hexo/helper/cdn')(hexo);
require('hexo-component-inferno/lib/hexo/helper/page')(hexo);
require('hexo-component-inferno/lib/hexo/tag/message')(hexo);
require('hexo-component-inferno/lib/hexo/tag/tabs')(hexo);
require('hexo-component-inferno/lib/core/view').init(hexo);
};
15 changes: 15 additions & 0 deletions include/util/console.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let chalk;
try {
chalk = require('chalk'); // eslint-disable-line node/no-extraneous-require
} catch (e) { }

module.exports = new Proxy({}, {
get(obj, prop) {
if (chalk) {
return chalk[prop];
}
return function() {
return arguments.length === 1 ? arguments[0] : arguments;
};
}
});
33 changes: 33 additions & 0 deletions layout/_layout/nexmoe/body.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { Component } = require("inferno");

module.exports = class extends Component {
render() {
const { partial } = this.props;
const Content = require(`./content`);
const Footer = require(`./footer`);

return (
<>
<div
id="nexmoe-header"
dangerouslySetInnerHTML={{
__html: partial("_layout/nexmoe/header"),
}}
></div>
<div id="nexmoe-content">
<Content {...this.props} />
<div
class="nexmoe-post-right"
dangerouslySetInnerHTML={{
__html: partial("_partial/right"),
}}
></div>
</div>

<div id="nexmoe-footer">
<Footer {...this.props} />
</div>
</>
);
}
};
14 changes: 14 additions & 0 deletions layout/_layout/nexmoe/content.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { Component } = require("inferno");

module.exports = class extends Component {
render() {
const { body } = this.props;

return (
<div
class="nexmoe-primary"
dangerouslySetInnerHTML={{ __html: body }}
></div>
);
}
};
11 changes: 11 additions & 0 deletions layout/_layout/nexmoe/footer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { Component } = require("inferno");

module.exports = class extends Component {
render() {
const { body } = this.props;

return (
<></>
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
</a>
<% } %>
</div>
<aside id="nexmoe-sidebar">
<% theme.widgets.forEach(function(widget){ %>
<% if(widget.enable){ %>
<%- partial('_widget/' + widget.name, {options: widget.options}) %>
<% }}) %>
</aside>

<% theme.widgets.forEach(function(widget){ %>
<% if(widget.enable){ %>
<%- partial('_widget/' + widget.name, {options: widget.options}) %>
<% }}) %>

<div class="nexmoe-copyright">
&copy; <%= date(new Date(), 'YYYY') %> <%= config.author || config.title %>
<%= __('Powered by') %> <a href="http://hexo.io/" target="_blank">Hexo</a>
Expand Down
3 changes: 0 additions & 3 deletions layout/_layout/single/content.ejs

This file was deleted.

33 changes: 33 additions & 0 deletions layout/_layout/xiaoshu/body.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { Component } = require("inferno");

module.exports = class extends Component {
render() {
const { partial } = this.props;
const Header = require(`./header`);
const Content = require(`./content`);
const Footer = require(`./footer`);

return (
<>
<div id="nexmoe-header">
<Header {...this.props} />
</div>
<div id="nexmoe-content">
<div class="nexmoe-container">
<Content {...this.props} />
<div
class="nexmoe-post-right"
dangerouslySetInnerHTML={{
__html: partial("_partial/right"),
}}
></div>
</div>
</div>

<div id="nexmoe-footer">
<Footer {...this.props} />
</div>
</>
);
}
};
9 changes: 9 additions & 0 deletions layout/_layout/xiaoshu/content.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { Component } = require("inferno");

module.exports = class extends Component {
render() {
const { body } = this.props;

return <div dangerouslySetInnerHTML={{ __html: body }}></div>;
}
};
30 changes: 30 additions & 0 deletions layout/_layout/xiaoshu/footer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { Component } = require("inferno");

module.exports = class extends Component {
render() {
const { config, date, theme, __ } = this.props;

return (
<>
<div class="nexmoe-container">
&copy; {date(new Date(), "YYYY")}{" "}
{config.author || config.title}
{__("Powered by")}
<a href="http://hexo.io/" target="_blank">
Hexo
</a>
&
<a
href="https://github.com/theme-nexmoe/hexo-theme-nexmoe"
target="_blank"
>
Nexmoe
</a>
<div
dangerouslySetInnerHTML={{ __html: theme.slotSidebar }}
></div>
</div>
</>
);
}
};
30 changes: 30 additions & 0 deletions layout/_layout/xiaoshu/header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { Component } = require("inferno");

module.exports = class extends Component {
render() {
const { config, date, theme, __ } = this.props;

return (
<>
<div class="nexmoe-container">
&copy; {date(new Date(), "YYYY")}{" "}
{config.author || config.title}
{__("Powered by")}
<a href="http://hexo.io/" target="_blank">
Hexo
</a>
&
<a
href="https://github.com/theme-nexmoe/hexo-theme-nexmoe"
target="_blank"
>
Nexmoe
</a>
<div
dangerouslySetInnerHTML={{ __html: theme.slotSidebar }}
></div>
</div>
</>
);
}
};
Loading

0 comments on commit 6e35382

Please sign in to comment.