Skip to content
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

Preserve order when updating font #54

Open
m-weeks opened this issue Feb 11, 2019 · 9 comments
Open

Preserve order when updating font #54

m-weeks opened this issue Feb 11, 2019 · 9 comments

Comments

@m-weeks
Copy link

m-weeks commented Feb 11, 2019

Currently the characters will be generated in alphabetical order of the file names, but if an icon is added that isn't at the bottom of the list, it will be inserted and the character codes will be thrown off. This is fine for when you are using the class names for icons, but not when the character codes matter.

A workaround would be to prefix all your icons with a number:
ex: 01.close.svg, 02.arrow.svg, etc.
But it would ideally be nicer to keep the order without worrying about file names.

@TheBrainTeam
Copy link

TheBrainTeam commented Feb 12, 2019

I realized it too late as it went to prod 😩 then I was keeping the file names prefix as zz1, zz2.... to get the new files to the end but later realized after zz9 it takes zz10 before zz1 😡 like a weird dictionary then I had to name it Zzz1a zzz1b now the classnames are a mess. I couldn't do anything as it all went to prod and uses both classnames & content codes

@gearsandcode
Copy link

gearsandcode commented Feb 19, 2019

It looks like that's what the --codepoints option is for, I can't get it to work though.

Here's what I'm trying:

icon-font-generator icons/*.svg -o dist --codepoints icon-codepoints.json

My codepoints file looks like this:
icon-codepoints.json
{ "icon1": "\\e939", "icon2": "\\e90a" }

The codepoints file seems to get ignored though.

===

I am able to get it working using webfonts-generator though using this gulp script, but that project is no longer maintained and this one looks to be much better.

const webfontsGenerator = require('webfonts-generator');

gulp.task('iconfont', function() {
  webfontsGenerator({
    codepoints: {
      'icon1': '\e90a',
      'icon2': '\e939'
    },
    files: [
      '../assets/icons/icon1.svg',
      '../assets/icons/icon2.svg',
    ],
    dest: 'dest/',
  }, function(error) {
    if (error) {
      console.log('Fail!', error);
    } else {
      console.log('Done!');
    }
  })
});

@Hammie
Copy link

Hammie commented Feb 27, 2019

Had the same problem and managed to solve it using the --codepoints parameter. It takes just a simple icon name => character number as input json:

{
	"icon": "0xf100",
	"icon2": "0xf101",
	"icon3": "0xf102"
}

@gargiguy
Copy link

Had the same problem and managed to solve it using the --codepoints parameter. It takes just a simple icon name => character number as input json:

{
	"icon": "0xf100",
	"icon2": "0xf101",
	"icon3": "0xf102"
}

Can you please share your full function string / settings?
For some reason I can't get it to get it to work...

@Hammie
Copy link

Hammie commented Mar 19, 2019

Can you please share your full function string / settings?
For some reason I can't get it to get it to work...

I don't have the code with me right now but if I remember correctly:

I have a file called codepoints.json that contains

{
	"folder": "0xf100",
	"folder_open": "0xf101",
	"folder_closed": "0xf102"
}

and a folder containing 3 icons icons/folder.svg, icons/folder_open.svg and icons/folder_closed.svg

Then I generate the font using icon-font-generator icons/*.svg --codepoints codepoints.json

@demiro
Copy link

demiro commented Jun 7, 2019

this is still an issue... if you provide the codepoints they just get overwritten anyways.... when debugging
log(options, JSON.stringify(options.codepointsMap).green);

after line 40 in index.js

options.codepointsMap = await getCodepointsMap(options.codepoints)

options.codepointsMap = await getCodepointsMap(options.codepoints)

I get

something in the lines like this:

{ icon1: null icon2: null, icon3: null }

this, after I created it the first time and the second time I passed the json creted as codepoints:

{ "icon1": "\\f101", "icon2": "\\f102", "icon3": "\\f103", }

can someone shed some light on this? I think it get's messed up on line #160

codepointsMap[propName] = Number.parseInt(codepointsMap[propName])

@Hammie
Copy link

Hammie commented Jun 7, 2019

this is still an issue... if you provide the codepoints they just get overwritten anyways.... when debugging
log(options, JSON.stringify(options.codepointsMap).green);

after line 40 in index.js

options.codepointsMap = await getCodepointsMap(options.codepoints)

options.codepointsMap = await getCodepointsMap(options.codepoints)

I get

something in the lines like this:

{ icon1: null icon2: null, icon3: null }

this, after I created it the first time and the second time I passed the json creted as codepoints:

{ "icon1": "\\f101", "icon2": "\\f102", "icon3": "\\f103", }

can someone shed some light on this? I think it get's messed up on line #160

codepointsMap[propName] = Number.parseInt(codepointsMap[propName])

You should use the hexadecimal notation for the unicode codepoints:
{ "icon1": "0xf101", "icon2": "0xf102", "icon3": "0xf103", }

If you need to use unicode literals, use the correct javascript notation ("\uf101", "\uf102") and update the code to get the character code:

const codePoint = codepointsMap[propName];
codepointsMap[propName] = Number.parseInt(codePoint) || codePoint.charCodeAt(0);

@migacz1125
Copy link

migacz1125 commented Oct 30, 2019

@Hammie @tancredi do You plan add code:
const codePoint = codepointsMap[propName]; codepointsMap[propName] = Number.parseInt(codePoint) || codePoint.charCodeAt(0);
to some PR and merge to new version of icon-font-generator ?

@Hammie
Copy link

Hammie commented Oct 30, 2019

@Hammie @tancredi do You plan add code:
const codePoint = codepointsMap[propName]; codepointsMap[propName] = Number.parseInt(codePoint) || codePoint.charCodeAt(0);
to some PR and merge to new version of icon-font-generator ?

I've updated the code to support unicode entries and added a sanity check so you get an error message if it does not understand the input.

PR should be linked to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants