Skip to content

Commit b02ad56

Browse files
authored
Add X-PHONETIC-ORG field and the number of items next to group name (#529)
* Add X-PHONETIC-ORG field to enable alphabetical sorting on English language systems * Add the number of items in each group next to its nam * chore: replace hardcoded usernames with variables
1 parent 96ab0e5 commit b02ad56

File tree

7 files changed

+43
-8
lines changed

7 files changed

+43
-8
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ jobs:
2929
env:
3030
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
3131
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
DOCKER_USERNAME: ${{ vars.Docker_USERNAME }}
33+
GITHUB_USERNAME: ${{ github.actor }}
3234
run: |
3335
IMAGE_VERSION=`cat package.json | jq -r '.version'`
34-
echo $DOCKER_TOKEN | docker login -u metowolf --password-stdin
35-
docker build -t metowolf/vcards:$IMAGE_VERSION .
36-
docker push metowolf/vcards:$IMAGE_VERSION
37-
echo $GITHUB_TOKEN | docker login ghcr.io -u metowolf --password-stdin
38-
docker build -t ghcr.io/metowolf/vcards:$IMAGE_VERSION .
39-
docker push ghcr.io/metowolf/vcards:$IMAGE_VERSION
36+
echo $DOCKER_TOKEN | docker login -u $DOCKER_USERNAME --password-stdin
37+
docker build -t $DOCKER_USERNAME/vcards:$IMAGE_VERSION .
38+
docker push $DOCKER_USERNAME/vcards:$IMAGE_VERSION
39+
echo $GITHUB_TOKEN | docker login ghcr.io -u $GITHUB_USERNAME --password-stdin
40+
docker build -t ghcr.io/$GITHUB_USERNAME/vcards:$IMAGE_VERSION .
41+
docker push ghcr.io/$GITHUB_USERNAME/vcards:$IMAGE_VERSION

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"image-size": "^1.0.2",
2626
"joi": "^17.9.2",
2727
"js-yaml": "^4.1.0",
28+
"pinyin-pro": "^3.26.0",
2829
"pretty-bytes": "^6.1.1",
2930
"read-chunk": "^4.0.3",
3031
"vcards-js": "^2.10.0"

src/gulpfile.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ const createRadicale = () => {
5858
return fs.statSync(path.join('temp', f)).isDirectory();
5959
})
6060
folders.map(function(folder){
61-
fs.writeFileSync(path.join('temp', folder, '/.Radicale.props'), '{"D:displayname": "' + folder + '", "tag": "VADDRESSBOOK"}')
61+
const fileCount = fs.readdirSync(path.join('temp', folder))
62+
.filter(file => file.endsWith('.vcf'))
63+
.length;
64+
fs.writeFileSync(
65+
path.join('temp', folder, '/.Radicale.props'),
66+
`{"D:displayname": "${folder}(${fileCount})", "tag": "VADDRESSBOOK"}`
67+
)
6268
})
6369
return gulp.src('temp/**', {})
6470
}

src/plugins/vcard-ext.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs'
22
import yaml from 'js-yaml'
33
import vCardsJS from 'vcards-js'
44
import {execSync} from 'child_process'
5+
import addPhoneticField from '../utils/pinyin.js'
56

67
const plugin = (file, _, cb) => {
78
const path = file.path
@@ -26,6 +27,7 @@ const plugin = (file, _, cb) => {
2627

2728
let formatted = vCard.getFormattedString()
2829
formatted = formatted.replace(/REV:[\d\-:T\.Z]+/, 'REV:' + rev)
30+
formatted = addPhoneticField(formatted, 'ORG')
2931
file.contents = Buffer.from(formatted)
3032
cb(null, file)
3133
}

src/plugins/vcard.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs'
22
import yaml from 'js-yaml'
33
import vCardsJS from 'vcards-js'
4+
import addPhoneticField from '../utils/pinyin.js'
45

56
const plugin = (file, _, cb) => {
67
const path = file.path
@@ -21,7 +22,9 @@ const plugin = (file, _, cb) => {
2122
})
2223
}
2324
vCard.photo.embedFromFile(path.replace('.yaml', '.png'))
24-
file.contents = Buffer.from(vCard.getFormattedString())
25+
let formatted = vCard.getFormattedString()
26+
formatted = addPhoneticField(formatted, 'ORG')
27+
file.contents = Buffer.from(formatted)
2528
cb(null, file)
2629
}
2730

src/utils/pinyin.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { pinyin } from 'pinyin-pro'
2+
3+
const addPhoneticField = (text, fieldName) => {
4+
const regex = new RegExp(`${fieldName};CHARSET=UTF-8:(.*)\r?\n`, 'g');
5+
return text.replace(regex, (match, value) => {
6+
const hasChinese = /[\u4e00-\u9fa5]/.test(value);
7+
const pinyinText = hasChinese ?
8+
pinyin(value, { toneType: 'none', nonZh: 'consecutive', type: 'array' })
9+
.map(item => item[0].toUpperCase() + item.slice(1))
10+
.join(' ')
11+
: value;
12+
return `${match}X-PHONETIC-${fieldName};CHARSET=UTF-8:${pinyinText}\n`;
13+
});
14+
};
15+
16+
export default addPhoneticField;

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,6 +2351,11 @@ pinkie@^2.0.0:
23512351
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
23522352
integrity sha512-MnUuEycAemtSaeFSjXKW/aroV7akBbY+Sv+RkyqFjgAe73F+MR0TBWKBRDkmfWq/HiFmdavfZ1G7h4SPZXaCSg==
23532353

2354+
pinyin-pro@^3.26.0:
2355+
version "3.26.0"
2356+
resolved "https://registry.yarnpkg.com/pinyin-pro/-/pinyin-pro-3.26.0.tgz#9e3b8a9f848263b81552d56e9319f520f7709ad6"
2357+
integrity sha512-HcBZZb0pvm0/JkPhZHWA5Hqp2cWHXrrW/WrV+OtaYYM+kf35ffvZppIUuGmyuQ7gDr1JDJKMkbEE+GN0wfMoGg==
2358+
23542359
pkg-conf@^4.0.0:
23552360
version "4.0.0"
23562361
resolved "https://registry.yarnpkg.com/pkg-conf/-/pkg-conf-4.0.0.tgz#63ace00cbacfa94c2226aee133800802d3e3b80c"

0 commit comments

Comments
 (0)