8000 fix: new icons cause codepoints to change by lllziyu98 · Pull Request #57 · qwd/Icons · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: new icons cause codepoints to change #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions build/build-alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,47 @@ const {generateFonts} = require('fantasticon');
const codepoints = require('../font/qweather-icons.json');
const iconWords = require('../icons-list.json');
let generateFontsOption = require('../fantasticonrc')
const path = require("path");
const fs = require("fs");
const preIconsFile = '../font/pre-qweather-icons.json'

function iconTrans(key) {
let name = ''
iconWords.forEach((item, index) => {
if (item.icon_code == key) {
name = item.icon_name
}
})
return name
let exist = iconWords.find(item => item.icon_code == key)
return exist ? exist.icon_name : key
}

function getAllCodePoints() {
let newCodepoints = {}
for (let i in codepoints) {
newCodepoints[iconTrans(i)] = codepoints[i]
}
return Object.assign(codepoints, newCodepoints)
function getAllCodePoints(onlyCodepoints) {
let onlyNamePoints = {}
for (let i in onlyCodepoints) {
onlyNamePoints[iconTrans(i)] = onlyCodepoints[i]
}
return Object.assign(onlyCodepoints, onlyNamePoints)
}

generateFontsOption.codepoints = getAllCodePoints()
generateFonts(generateFontsOption)
fs.readFile(path.join(__dirname, preIconsFile), 'utf8', (err, data) => {
let preCodepoints = err ? {} : JSON.parse(data)
let >
let noHave = {}
for (let i in codepoints) {
if (preCodepoints[i]) {
onlyCodepoints[i] = preCodepoints[i]
} else {
noHave[i] = codepoints[i]
}
}
const values = Object.values(onlyCodepoints).sort((a, b) => a - b);
if (values.length > 0) {
let start = values[values.length - 1]
for (let i in noHave) {
start++
onlyCodepoints[i] = start
}
} else {
>
}
if (!err) {
fs.unlink(path.join(__dirname, preIconsFile), (deleteErr) => {});
}
generateFontsOption.codepoints = getAllCodePoints(onlyCodepoints)
generateFonts(generateFontsOption)
});
23 changes: 23 additions & 0 deletions build/keep-last-icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require('fs')
const path = require('path')

const file = {
source: 'qweather-icons.json',
output: 'pre-qweather-icons.json'
}

function copyFile (file) {
let sourceFile = path.join(__dirname, '../font/' + file.source)
let outputFile = path.join(__dirname, '../font/' + file.output)

fs.readFile(sourceFile, 'utf8', (err, data) => {
if (err) {
console.error('读取源文件时出错:', err);
return;
}

fs.writeFile(outputFile, data, 'utf8', (err) => {});
});
}

copyFile(file)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"icons": "npm run icons-main && npm run icons-font",
"icons-main": "node build/build-svgs.js",
"icons-zip": "cross-env-shell \"rm -rf QWeather-Icons-$npm_package_version && mkdir QWeather-Icons-$npm_package_version && cp -r icons/ QWeather-Icons-$npm_package_version/icons && cp -r font/ QWeather-Icons-$npm_package_version/font && cp LICENSE QWeather-Icons-$npm_package_version && cp README.md QWeather-Icons-$npm_package_version && zip -r9 QWeather-Icons-$npm_package_version.zip QWeather-Icons-$npm_package_version && rm -rf QWeather-Icons-$npm_package_version\"",
"icons-font": "fantasticon && node build/build-alias.js",
"icons-font": "node build/keep-last-icons.js && fantasticon && node build/build-alias.js",
"docs-build:docs": "hugo --cleanDestinationDir",
"docs-build:css": "npx tailwindcss -i ./docs/assets/css/tw.css -o ./docs/assets/css/style.css -m",
"docs-build": "npm run docs-build:css && npm run docs-build:docs",
Expand Down
0