Skip to content

Commit

Permalink
update 8.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
PGzxc committed Jun 6, 2022
1 parent fe09ff9 commit d91fb2b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 75 deletions.
73 changes: 23 additions & 50 deletions lib/highlight.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,28 @@
const https = require('https');
const path = require('path');
const fs = require('fs');
const { spawnSync } = require('child_process');
const path = require('path');
const table = require('text-table');
const { green, magenta, red } = require('chalk');
const { resolve, highlightTheme } = require('hexo-theme-next/scripts/events/lib/utils');

https.get('https://api.github.com/repos/next-theme/hexo-theme-next/releases', {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
}
}, res => {
let data = '';
res.on('data', chunk => {
data += chunk;
});
res.on('end', () => {
if (res.statusCode === 200) {
data = JSON.parse(data);
parse(data);
}
});
}).on('error', err => {
console.error('Failded to download release messages.');
console.log(err);
});
function test(color) {
const reg = /^(#([\da-fA-F]{6}|[\da-fA-F]{3})|black|white|silver|grey|navy)$/;
return reg.test(color);
}

function parse(data) {
data.sort((a, b) => {
return new Date(b.created_at) - new Date(a.created_at);
});
data.forEach(release => {
const version = release.tag_name.replace('v', '');
console.log('Processing version %s', version);
const filename = path.join(__dirname, `../source/_posts/next-${version.split('.').join('-')}-released.md`);
if (fs.existsSync(filename)) return;
const time = release.published_at.replace('T', ' ').replace('Z', '');
const body = release.body
.replace(/#(\d{1,4})/g, '[#$1](https://github.com/next-theme/hexo-theme-next/pull/$1)')
.replace(/([0-9a-f]{7})([0-9a-f]{33})/g, '[$1](https://github.com/next-theme/hexo-theme-next/commit/$1$2)')
.replace(/\r\n/g, '\n')
.trim();
const content = `---
title: NexT ${version} Released
date: ${time}
---
const basename = resolve('highlight.js', 'styles/');
const list = ['', 'base16/'].flatMap(relative => {
return fs.readdirSync(path.join(basename, relative))
.filter(name => name.endsWith('.css'))
.map(name => highlightTheme((relative + name).replace('.css', '')))
.filter(({ background, foreground }) => {
return !(test(background) && test(foreground));
});
});

${body}
console.log(table(list.map(({ file, background, foreground }) => {
return [green(file.replace(basename, '')), magenta(background.trim()), red(foreground.trim())];
})));

[Detailed changes for NexT v${version}](https://github.com/next-theme/hexo-theme-next/releases/tag/v${version})
`;
fs.writeFileSync(filename, content);
});
spawnSync('npm', ['version', data[0].tag_name.replace('v', ''), '-m', `Release ${data[0].tag_name}`, '--force'], {
stdio: "inherit"
});
}
fs.writeFileSync(path.join(__dirname, '../source/highlight/unavailable.js'), `// This file is automatically generated using \`npm run highlight\`
const unavailable = ${JSON.stringify(list.map(({ file }) => file.replace(basename, '').replace('.css', '')))};
`);
73 changes: 50 additions & 23 deletions lib/update.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
const fs = require('fs');
const https = require('https');
const path = require('path');
const table = require('text-table');
const { green, magenta, red } = require('chalk');
const { resolve, highlightTheme } = require('hexo-theme-next/scripts/events/lib/utils');

function test(color) {
const reg = /^(#([\da-fA-F]{6}|[\da-fA-F]{3})|black|white|silver|grey|navy)$/;
return reg.test(color);
}
const fs = require('fs');
const { spawnSync } = require('child_process');

const basename = resolve('highlight.js', 'styles/');
const list = ['', 'base16/'].flatMap(relative => {
return fs.readdirSync(path.join(basename, relative))
.filter(name => name.endsWith('.css'))
.map(name => highlightTheme((relative + name).replace('.css', '')))
.filter(({ background, foreground }) => {
return !(test(background) && test(foreground));
});
https.get('https://api.github.com/repos/next-theme/hexo-theme-next/releases', {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
}
}, res => {
let data = '';
res.on('data', chunk => {
data += chunk;
});
res.on('end', () => {
if (res.statusCode === 200) {
data = JSON.parse(data);
parse(data);
}
});
}).on('error', err => {
console.error('Failded to download release messages.');
console.log(err);
});

console.log(table(list.map(({ file, background, foreground }) => {
return [green(file.replace(basename, '')), magenta(background.trim()), red(foreground.trim())];
})));
function parse(data) {
data.sort((a, b) => {
return new Date(b.created_at) - new Date(a.created_at);
});
data.forEach(release => {
const version = release.tag_name.replace('v', '');
console.log('Processing version %s', version);
const filename = path.join(__dirname, `../source/_posts/next-${version.split('.').join('-')}-released.md`);
if (fs.existsSync(filename)) return;
const time = release.published_at.replace('T', ' ').replace('Z', '');
const body = release.body
.replace(/#(\d{1,4})/g, '[#$1](https://github.com/next-theme/hexo-theme-next/pull/$1)')
.replace(/([0-9a-f]{7})([0-9a-f]{33})/g, '[$1](https://github.com/next-theme/hexo-theme-next/commit/$1$2)')
.replace(/\r\n/g, '\n')
.trim();
const content = `---
title: NexT ${version} Released
date: ${time}
---
${body}
fs.writeFileSync(path.join(__dirname, '../source/highlight/unavailable.js'), `// This file is automatically generated using \`npm run highlight\`
const unavailable = ${JSON.stringify(list.map(({ file }) => file.replace(basename, '').replace('.css', '')))};
`);
[Detailed changes for NexT v${version}](https://github.com/next-theme/hexo-theme-next/releases/tag/v${version})
`;
fs.writeFileSync(filename, content);
});
spawnSync('npm', ['version', data[0].tag_name.replace('v', ''), '-m', `Release ${data[0].tag_name}`, '--force'], {
stdio: "inherit"
});
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "theme-next-docs",
"version": "8.11.1",
"version": "8.12.1",
"private": true,
"hexo": {
"version": "6.2.0"
Expand Down Expand Up @@ -41,7 +41,7 @@
"hexo-renderer-stylus": "2.1.0",
"hexo-server": "3.0.0",
"hexo-symbols-count-time": "^0.7.1",
"hexo-theme-next": "8.11.1",
"hexo-theme-next": "8.12.1",
"hexo-util": "^2.6.1"
},
"devDependencies": {
Expand Down

0 comments on commit d91fb2b

Please sign in to comment.