-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加 CardDav 服务器 Radicale 输出格式的支持 (#232)
* add: vcard-ext.js add uid & REV to vCard * update: add radicale script * fix * fix * update: ignore radicale
- Loading branch information
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ temp | |
public | ||
*.zip | ||
.DS_Store | ||
radicale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import fs from 'fs' | ||
import yaml from 'js-yaml' | ||
import vCardsJS from 'vcards-js' | ||
import {execSync} from 'child_process' | ||
|
||
const plugin = (file, _, cb) => { | ||
const path = file.path | ||
const data = fs.readFileSync(path, 'utf8') | ||
const json = yaml.load(data) | ||
|
||
let vCard = vCardsJS() | ||
vCard.isOrganization = true | ||
for (const [key, value] of Object.entries(json.basic)) { | ||
vCard[key] = value | ||
} | ||
|
||
if (!vCard.uid){ | ||
vCard.uid = vCard.organization | ||
} | ||
|
||
vCard.photo.embedFromFile(path.replace('.yaml', '.png')) | ||
let lastYamlChangeDateString = execSync('git log -1 --pretty="format:%ci" ' + path).toString().trim().replace(/\s\+\d+/, '') | ||
let lastPngChangeDateString = execSync('git log -1 --pretty="format:%ci" ' + path.replace('.yaml', '.png')).toString().trim().replace(/\s\+\d+/, '') | ||
|
||
let rev = new Date(Math.max(new Date(lastYamlChangeDateString), new Date(lastPngChangeDateString))).toISOString() | ||
|
||
let formatted = vCard.getFormattedString() | ||
formatted = formatted.replace(/REV:[\d\-:T\.Z]+/, 'REV:' + rev) | ||
file.contents = Buffer.from(formatted) | ||
cb(null, file) | ||
} | ||
|
||
export default plugin |