Skip to content

Commit

Permalink
update to Octicons v9.1.1, regenerate
Browse files Browse the repository at this point in the history
Use a fixed Octicon width and height of 16 px, and simplify
the generateOcticon and parseOcticon functions that do this.

Change octicon.Height field type to float64 because some Octicons
now have non-integer heights. See primer/octicons#346.

Follows primer/octicons#324.
  • Loading branch information
dmitshur committed Sep 30, 2019
1 parent 9ff1a4c commit 30220ef
Show file tree
Hide file tree
Showing 4 changed files with 903 additions and 114 deletions.
2 changes: 1 addition & 1 deletion _data/data.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Package octicon provides GitHub Octicons.
package octicon

//go:generate curl -L -o octicons.tgz https://registry.npmjs.org/octicons/-/octicons-8.1.0.tgz
//go:generate curl -L -o octicons.tgz https://registry.npmjs.org/@primer/octicons/-/octicons-9.1.1.tgz
//go:generate tar -xf octicons.tgz package/build/data.json
//go:generate rm octicons.tgz
//go:generate mv package/build/data.json _data/data.json
Expand Down
14 changes: 5 additions & 9 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func SetSize(icon *html.Node, size int) *html.Node {
type octicon struct {
Path string
Width int
Height int
Height float64
}

func generateAndWriteOcticon(w io.Writer, octicons map[string]octicon, name string) {
Expand Down Expand Up @@ -135,6 +135,8 @@ const (
heightAttrIndex = 2
)

// TODO: Short-circuit generateOcticon and parseOcticon.

func generateOcticon(o octicon) (svgXML string) {
path := o.Path
if strings.HasPrefix(path, `<path fill-rule="evenodd" `) {
Expand All @@ -143,8 +145,8 @@ func generateOcticon(o octicon) (svgXML string) {
}
// Note, SetSize relies on the absolute position of the width, height attributes.
// Keep them in sync with widthAttrIndex and heightAttrIndex.
return fmt.Sprintf(`<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="%d" viewBox="0 0 %d %d">%s</svg>`,
o.Width, o.Height, o.Width, o.Height, path)
return fmt.Sprintf(`<svg xmlns="http://www.w3.org/2000/svg" width=16 height=16 viewBox="0 0 %v %v">%s</svg>`,
o.Width, o.Height, path)
}

func parseOcticon(svgXML string) *html.Node {
Expand All @@ -154,12 +156,6 @@ func parseOcticon(svgXML string) *html.Node {
}
svg := e[0].LastChild.FirstChild // TODO: Is there a better way to just get the <svg>...</svg> element directly, skipping <html><head></head><body><svg>...</svg></body></html>?
svg.Parent.RemoveChild(svg)
for i, attr := range svg.Attr {
if attr.Namespace == "" && attr.Key == "width" {
svg.Attr[i].Val = "16"
break
}
}
svg.Attr = append(svg.Attr, html.Attribute{Key: atom.Style.String(), Val: `fill: currentColor; vertical-align: top;`})
return svg
}
Loading

0 comments on commit 30220ef

Please sign in to comment.