Skip to content

Commit

Permalink
Breaking: rewrite using rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
Lhcfl committed Sep 3, 2024
1 parent deb6a08 commit 49417ae
Show file tree
Hide file tree
Showing 31 changed files with 1,183 additions and 835 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test_and_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
run: |
git clone https://github.com/hexojs/hexo-theme-unit-test.git unit_test
git clone https://github.com/Lhcfl/hexo-theme-anatolo.git unit_test/themes/Anatolo
cd unit_test/themes/Anatolo
yarn
cd ../../..
cp ./.github/asserts/anatolo_config.yml unit_test/themes/Anatolo/_config.yml
cp ./.github/asserts/hexo_config.yml unit_test/_config.yml
cp ./.github/asserts/_posts/* unit_test/source/_posts/
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
_config.yml
source/images/favicon.png
source/images/logo.png
node_modules
node_modules
source/js_complied
source/js/deprecated
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/*.min.js
**/*.min.css
**/*.min.css
source/js_complied
8 changes: 8 additions & 0 deletions includes/tasks/rollup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const cp = require('child_process');

module.exports = function (hexo) {
hexo.log.info('building js');
console.log(cp);
cp.execSync('yarn build', { cwd: './themes/Anatolo', stdio: 'inherit' });
hexo.log.info('build successful!');
};
2 changes: 0 additions & 2 deletions layout/partial/components/search.pug
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
script
!= '(async function(){ if (Anatolo.search == null) await Anatolo.getMsg("search-init"); Anatolo.search.config = {translation:{posts:"' + __("insight.posts") + '",pages:"' + __("insight.pages") + '",categories:"' + __("insight.categories") + '",tags:"' + __("insight.tags") + '",untitled:"' + __("insight.untitled") + '",} }; })()'
//- script(src=url_for("js/insight.js"), defer)
script(src=url_for("js/search.js"), defer)
.searchbox.ins-search.modal-cover
.searchbox-container.ins-search-container.modal-container
.searchbox-input-wrapper
Expand Down
18 changes: 2 additions & 16 deletions layout/partial/head.pug
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ meta(content="yes", name="apple-mobile-web-app-capable")
meta(content="black", name="apple-mobile-web-app-status-bar-style")
meta(content="telephone=no", name="format-detection")

meta#site_root_url(data=url_for("/"))
meta#site_data_static(data-url=url_for("/"))
meta#default-theme(data=theme.defaultTheme == "dark-mode" ? "dark" : "light")

meta(name="renderer", content="webkit")
Expand All @@ -31,23 +31,9 @@ link(rel="stylesheet", href=url_for("css/insight.css"))
link(rel="stylesheet", href=url_for("css/search.css"))
link(rel="alternate", type="application/atom+xml", title="ATOM 1.0", href="/atom.xml")

script(src=url_for("js/utils/index.js"))
script(src=url_for("js/lib/eventemitter3.umd.min.js"))
script(
src="https://code.jquery.com/jquery-3.7.1.min.js",
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=",
crossorigin="anonymous"
)
script(src="https://cdn.jsdelivr.net/npm/[email protected]")
script(src=url_for("js/lib/jquery-migrate-1.2.1.min.js"))
script(src=url_for("js/lib/jquery.appear.js"))
script(src=url_for("js/anatolo.js"))
script(src=url_for("js/router.js"))
script(src=url_for("js/darkLightToggle.js"))
script(src=url_for("js/share.js"))
script(src=url_for("js_complied/bundle.js"))
if theme.Baidutongji
script(src=url_for("js/baidu-tongji.js"))

include comments
+require_comment_scripts
script(src=url_for("js/load-comment.js"))
2 changes: 1 addition & 1 deletion layout/partial/nav.pug
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
a.fa.fa-search(onclick="Anatolo.search.openWindow();")
if theme.rightbtn.darkLightToggle
li
a.far.fa-sun(onclick="darkLightToggle();")
a.far.fa-sun(onclick="Anatolo.darkLightToggle();")
.avatar
if theme.rightbtn.avatar
img(src=url_for(theme.avatar))
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@
"private": true,
"scripts": {
"format:stylus": "yarn stylus-supremacy format ./source/css/**/*.styl -r --options .supermacy.yml",
"format:pretty": "prettier --write ./{includes,languages,layout,scripts,source}/**/*.{pug,js,css}",
"format:pretty": "prettier --write ./{includes,languages,layout,scripts,source,src}/**/*.{pug,js,css,ts}",
"lint": "yarn eslint . --fix",
"format": "yarn format:stylus && yarn format:pretty"
"format": "yarn format:stylus && yarn format:pretty",
"build": "yarn rollup -c ./rollup.config.mjs"
},
"dependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"hexo-renderer-pug": "^0.0.5",
"hexo-renderer-stylus": "^0.2.3"
"hexo-renderer-stylus": "^0.2.3",
"jquery": "^3.7.1",
"rollup": "^4.21.2",
"typescript": "^5.5.4"
},
"devDependencies": {
"@prettier/plugin-pug": "^3.0.0",
Expand Down
38 changes: 38 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from "@rollup/plugin-typescript";
import terser from '@rollup/plugin-terser';

export default [
// browser-friendly UMD build
{
input: 'src/main.ts',
output: {
name: 'main.js',
file: "source/js_complied/bundle.js",
// format: 'umd',
format: 'umd',
},
plugins: [
resolve(), // so Rollup can find `ms`
commonjs(), // so Rollup can convert `ms` to an ES module
typescript(),
terser(),
],
},

// CommonJS (for Node) and ES module (for bundlers) build.
// (We could have three entries in the configuration array
// instead of two, but it's quicker to generate multiple
// builds from a single configuration where possible, using
// an array for the `output` option, where we can specify
// `file` and `format` for each target)
// {
// input: 'src/main.js',
// external: ['ms'],
// output: [
// { file: pkg.main, format: 'cjs' },
// { file: pkg.module, format: 'es' },
// ],
// },
];
1 change: 1 addition & 0 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require('../includes/tasks/welcome')(hexo);
require('../includes/tasks/rollup')(hexo);
require('../includes/generators/insight')(hexo);
require('../includes/generators/site_json')(hexo);
require('../includes/generators/tags')(hexo);
Expand Down
209 changes: 0 additions & 209 deletions source/js/anatolo.js

This file was deleted.

Loading

0 comments on commit 49417ae

Please sign in to comment.