Skip to content

Commit

Permalink
Add X-PHONETIC-ORG field and the number of items next to group name (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
lunanfo authored Feb 25, 2025
1 parent 96ab0e5 commit b02ad56
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 8 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ jobs:
env:
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_USERNAME: ${{ vars.Docker_USERNAME }}
GITHUB_USERNAME: ${{ github.actor }}
run: |
IMAGE_VERSION=`cat package.json | jq -r '.version'`
echo $DOCKER_TOKEN | docker login -u metowolf --password-stdin
docker build -t metowolf/vcards:$IMAGE_VERSION .
docker push metowolf/vcards:$IMAGE_VERSION
echo $GITHUB_TOKEN | docker login ghcr.io -u metowolf --password-stdin
docker build -t ghcr.io/metowolf/vcards:$IMAGE_VERSION .
docker push ghcr.io/metowolf/vcards:$IMAGE_VERSION
echo $DOCKER_TOKEN | docker login -u $DOCKER_USERNAME --password-stdin
docker build -t $DOCKER_USERNAME/vcards:$IMAGE_VERSION .
docker push $DOCKER_USERNAME/vcards:$IMAGE_VERSION
echo $GITHUB_TOKEN | docker login ghcr.io -u $GITHUB_USERNAME --password-stdin
docker build -t ghcr.io/$GITHUB_USERNAME/vcards:$IMAGE_VERSION .
docker push ghcr.io/$GITHUB_USERNAME/vcards:$IMAGE_VERSION
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"image-size": "^1.0.2",
"joi": "^17.9.2",
"js-yaml": "^4.1.0",
"pinyin-pro": "^3.26.0",
"pretty-bytes": "^6.1.1",
"read-chunk": "^4.0.3",
"vcards-js": "^2.10.0"
Expand Down
8 changes: 7 additions & 1 deletion src/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ const createRadicale = () => {
return fs.statSync(path.join('temp', f)).isDirectory();
})
folders.map(function(folder){
fs.writeFileSync(path.join('temp', folder, '/.Radicale.props'), '{"D:displayname": "' + folder + '", "tag": "VADDRESSBOOK"}')
const fileCount = fs.readdirSync(path.join('temp', folder))
.filter(file => file.endsWith('.vcf'))
.length;
fs.writeFileSync(
path.join('temp', folder, '/.Radicale.props'),
`{"D:displayname": "${folder}(${fileCount})", "tag": "VADDRESSBOOK"}`
)
})
return gulp.src('temp/**', {})
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/vcard-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs'
import yaml from 'js-yaml'
import vCardsJS from 'vcards-js'
import {execSync} from 'child_process'
import addPhoneticField from '../utils/pinyin.js'

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

let formatted = vCard.getFormattedString()
formatted = formatted.replace(/REV:[\d\-:T\.Z]+/, 'REV:' + rev)
formatted = addPhoneticField(formatted, 'ORG')
file.contents = Buffer.from(formatted)
cb(null, file)
}
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/vcard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs'
import yaml from 'js-yaml'
import vCardsJS from 'vcards-js'
import addPhoneticField from '../utils/pinyin.js'

const plugin = (file, _, cb) => {
const path = file.path
Expand All @@ -21,7 +22,9 @@ const plugin = (file, _, cb) => {
})
}
vCard.photo.embedFromFile(path.replace('.yaml', '.png'))
file.contents = Buffer.from(vCard.getFormattedString())
let formatted = vCard.getFormattedString()
formatted = addPhoneticField(formatted, 'ORG')
file.contents = Buffer.from(formatted)
cb(null, file)
}

Expand Down
16 changes: 16 additions & 0 deletions src/utils/pinyin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { pinyin } from 'pinyin-pro'

const addPhoneticField = (text, fieldName) => {
const regex = new RegExp(`${fieldName};CHARSET=UTF-8:(.*)\r?\n`, 'g');
return text.replace(regex, (match, value) => {
const hasChinese = /[\u4e00-\u9fa5]/.test(value);
const pinyinText = hasChinese ?
pinyin(value, { toneType: 'none', nonZh: 'consecutive', type: 'array' })
.map(item => item[0].toUpperCase() + item.slice(1))
.join(' ')
: value;
return `${match}X-PHONETIC-${fieldName};CHARSET=UTF-8:${pinyinText}\n`;
});
};

export default addPhoneticField;
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2351,6 +2351,11 @@ pinkie@^2.0.0:
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
integrity sha512-MnUuEycAemtSaeFSjXKW/aroV7akBbY+Sv+RkyqFjgAe73F+MR0TBWKBRDkmfWq/HiFmdavfZ1G7h4SPZXaCSg==

pinyin-pro@^3.26.0:
version "3.26.0"
resolved "https://registry.yarnpkg.com/pinyin-pro/-/pinyin-pro-3.26.0.tgz#9e3b8a9f848263b81552d56e9319f520f7709ad6"
integrity sha512-HcBZZb0pvm0/JkPhZHWA5Hqp2cWHXrrW/WrV+OtaYYM+kf35ffvZppIUuGmyuQ7gDr1JDJKMkbEE+GN0wfMoGg==

pkg-conf@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/pkg-conf/-/pkg-conf-4.0.0.tgz#63ace00cbacfa94c2226aee133800802d3e3b80c"
Expand Down

0 comments on commit b02ad56

Please sign in to comment.