Skip to content

Commit

Permalink
feat(script): generate .ics file
Browse files Browse the repository at this point in the history
  • Loading branch information
ourai committed Apr 25, 2024
1 parent 077486b commit 3f6d161
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
49 changes: 49 additions & 0 deletions .knosys/scripts/command/cal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { resolve: resolvePath } = require('path');
const { existsSync } = require('fs');
const ics = require('ics');

const { resolveRootPath, readData, saveData } = require('../helper');

function generateCalendar(data) {
const descriptors = [];

data.forEach(table => {
table.records.forEach(record => {
if (!record.任务名称 || !record.开始时间 || !['未开始', '进行中'].includes(record.任务状态)) {
return;
}

descriptors.push({
calName: '欧雷的开放生活',
productId: 'o.ourai.ws',
title: record.任务名称,
description: record.任务描述 || '',
start: record.开始时间,
startInputType: 'utc',
end: record.结束时间 || record.开始时间,
endInputType: 'utc',
status: record.任务状态 === '进行中' ? 'CONFIRMED' : 'TENTATIVE'
});
});
});

const { error, value } = ics.createEvents(descriptors);

if (error) {
return console.log(`[GEN ICS ERROR] ${error}`);
}

saveData(`${resolveRootPath()}/schedule.ics`, value);
}

module.exports = {
execute: dataSource => {
const srcPath = resolvePath(resolveRootPath(), dataSource);

if (!existsSync(srcPath)) {
return;
}

generateCalendar(readData(srcPath));
},
};
2 changes: 1 addition & 1 deletion .knosys/sites/default/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ theme_config:
parent:
text: Ourai.WS
url: https://ourai.ws/
text: 开放
text: 生活
color: "#0871ab"
copyright:
owner:
Expand Down
59 changes: 59 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
},
"devDependencies": {
"hexo-theme-lime": "0.0.0-alpha.3",
"ics": "^3.7.2",
"ksio": "0.0.3"
},
"scripts": {
"copy": "node .knosys/scripts copy",
"build": "node .knosys/scripts gen",
"clean": "rm -rf .asset-cache .cache .knosys/sites/*/.asset-cache .knosys/sites/*/.cache",
"start": "node .knosys/scripts serve",
"ics": "node .knosys/scripts cal",
"predeploy": "npm run clean",
"deploy": "node .knosys/scripts deploy"
}
Expand Down

0 comments on commit 3f6d161

Please sign in to comment.