logo.svg 中文文档教程

发布于 9年前 浏览 39 项目主页 更新于 3年前

logo.svg

生成一个 svg 徽标,然后您可以将其嵌入到 README.md 中

MIT 许可证

npm: build:?

功能:

  • Custom font, font size, letter spacing
  • Generate individual path for every char
  • Support any valid attributes and style
  • Handily cli

Install

要使用 logo 命令,请全局安装它:

$ npm install logo.svg -g

要使用 JavaScript API,请安装本地 logo.svg

$ npm install logo.svg --save

如果您同时需要 logo 命令和 JavaScript API,请以两种方式安装 logo.svg.js。

Usage

CLI

$ logo [options]

选项:

  -l, --logo ??? ............. The logo text. Default is the `name` of the `package.json`.
  -f, --font ??? ............. Specify the font path or url.
  -s, --fontSize ??? ......... Specify the font size. Default `72`.
  -o, --output ??? ........... Specify the output path. Default `logo.svg`
  -c, --config ??? ........... Specify the `.logorc` file.
  -O, --overwrite ............ Overwrite when a logo file exist. Default `true`.
  -k, --kerning .............. Take kerning information into account. Default `true`.
  -d, --divided .............. Generate individual path for every char. Default `false`.
  -V, --version .............. Print the current version.
  -h, --help ................. You're looking at it.
  -h, --help ??? ............. Show details for the specified command.

示例:

  $ logo
  $ logo -Odo ./logo/logo.svg
  $ logo --config ./logo/.logorc
  $ logo --help
  $ logo --help font
  $ logo --help config
  $ logo --version

JavaScript API

var logo = require('logo.svg');
// generate the svg string, then you can use it in you code
var svg = logo.generate(options);

Options

font

字体的路径或完整网址。 如果是 url,我们将异步加载字体,然后生成徽标。

如果路径是相对路径,则它相对于当前工作目录(process.cwd())。

如果路径是基本名称,例如 fontName.ttf,我们将首先尝试将其作为相对路径加载,如果失败,我们将从 preset 文件夹中搜索它,然后从系统和用户字体文件夹中搜索它。

预设文件夹为./fonts/,通过pull request贡献您的字体。

标志文字。 默认值是 package.json 中的name

x

文本开头的水平位置。 (默认值:0

y

文本基线的垂直位置。 (默认值:0

fontSize

文本的大小。 (默认值:72

spacing

字母间距。 (默认值:0

kerning

如果true 会考虑字距调整信息。 (默认值:true

divided

如果true 为每个字符生成单独的路径。 (默认值:false

grouped

如果 true 将单个 分组代码> 元素。 (默认值:false

title

如果指定,将在 的根处生成 </code>。 (默认:<code>logo</code>)

desc

如果指定,将在 的根处生成 。 (默认值:null

指定 相对于 的填充:

  • options.padding
  • options.paddingTop or options['padding-top']
  • options.paddingRight or options['padding-right']
  • options.paddingBottom or options['padding-bottom']
  • options.paddingLeft or options['padding-left']

;、 元素可以通过任何有效属性设置样式。

生成的具有以下默认属性:

{
    'version'    : '1.1',
    'xmlns'      : 'http://www.w3.org/2000/svg',
    'xmlns:xlink': 'http://www.w3.org/1999/xlink',
    'role'   : 'img',
    'width'  : width,
    'height' : height,
    'viewbox': [x, y, width, height].join(' ')
}

我们可以通过添加/更新/删除 >options.svg

options.svg = {
    'version': '',     // remove this attribute
    'role'   : 'logo', // update this attribute
    'fill'   : 'red'   // add some custiom styles
}

注意不能指定宽度高度viewbox

通过 options.path 设置 的样式。 如果 dividedtrue,我们可以通过 options.path? 设置单个 元素的样式,其中 < code>? 是 logo 中每个字符的索引:

// style for every path(s)
options.path  = {
    'fill': yellow
};

// style the first char
options.path0 = {
    'fill': '#FF0000',
    'stroke': '#000000'
};

options.g 指定 的样式一样代码> 元素。

.logorc

所有选项都可以在以下文件中指定:

  • .logorc.js
  • .logorc.yaml
  • .logorc.yml
  • .logorc.json
  • .logorc
  • The logo section in package.json

我们将尝试按顺序从这些文件加载​​配置,停止直到任何文件加载成功。

.logorc 示例:

font: Origami-Mommy-Pixellated.ttf
fontSzie: 72
output: logo.svg
# style the logo
path:
  fill: '#6ccb99'

package.json 示例:

{
  "name": "module",
  "version": "1.0.0",

  "logo": {
    "font": "Origami-Mommy-Pixellated.ttf",
    "fontSzie": 72,
    "output": "logo.svg",
    "path": {
      "fill": "#6ccb99"
    }
  },

}

出于安全考虑,SVG 无法从 README 中运行

由于潜在的跨站点脚本漏洞,我们不得不在 GitHub.com 上禁用 svg 图像渲染。

所以,我们不能通过原始url嵌入,rawgit.com很好地解决了这个问题。 对于每个请求,它都会从 GitHub 检索适当的文档,并且最重要的是,使用正确的 Content-Type 标头为其提供服务。

使用以下模式链接到您的 logo.svg:

https://cdn.rawgit.com/<repo-owner>/<repo>/<branch>/path/to.svg

为了确保 CDN 始终提供您想要的文件版本,请在文件路径中使用 git 标签或提交哈希而不是分支名称,并在推送时更新 URL文件的新版本。

因此,不要使用像 https://cdn.rawgit.com/user/repo/branch/file 这样的 URL,而使用像 https://cdn.rawgit.com/user 这样的 URL /repo/tag/filehttps://cdn.rawgit.com/user/repo/commit/file

嵌入代码如下所示:

![logo.svg](https://cdn.rawgit.com/<repo-owner>/<repo>/<branch>/path/to.svg)

<img alt="logo.svg" width="500" src="https://cdn.rawgit.com/<repo-owner>/<repo>/<branch>/path/to.svg">

Demos

font: 'gubblebum-glocky.ttf'
logo: 'npm '
output: './demos/gubblebum-blocky/npm.svg'
path:
  fill: '#cb3837'

npm

logo: 'divided'
font: 'origami-mommy.ttf'
output: './demos/origami-mommy/divided.svg'
divided: true
path:
  fill: '#6af72e'
path1:
  fill: '#c6e03c'
path2:
  fill: '#fc428f'
path3:
  fill: '#cea2fd'
path4:
  fill: '#fb3f24'
path5:
  fill: '#3cc8f6'
path6:
  fill: '#ff3e74'

divided

logo: 'Blocked'
font: 'blocked.ttf'
output: './demos/blocked/blocked.svg'
path:
  fill: '#fc174f'

blocked

logo: 'Square'
font: 'mk-zodnig-square.ttf'
fontSize: 96
output: './demos/mk-zodnig-square/square.svg'
path:
  fill: '#fd742d'
#  stroke: '#fd742d'

square

logo: 'Gubblebum '
font: 'gubblebum.ttf'
output: './demos/gubblebum/gubblebum.svg'
spacing: 10
divided: true
path:
  fill: '#6af72e'
path0:
  fill: '#fc428f'

gubbblebum

  • text2svg Convert text to svg path.
  • loadrc Load runtime configuration files for your module.

TODO

  • Support logo template.
  • What's your suggestion? Open an issue.

Contributing

非常欢迎拉取请求和星星。

对于错误和功能请求,请创建问题

logo.svg

Generate a svg logo, then you can embed it in you README.md

MIT License

npm: build:?

Feature:

  • Custom font, font size, letter spacing
  • Generate individual path for every char
  • Support any valid attributes and style
  • Handily cli

Install

To use the logo command, install it globally:

$ npm install logo.svg -g

To use the JavaScript API, install logo.svg locally:

$ npm install logo.svg --save

If you need both the logo command and the JavaScript API, install logo.svg.js both ways.

Usage

CLI

$ logo [options]

Options:

  -l, --logo ??? ............. The logo text. Default is the `name` of the `package.json`.
  -f, --font ??? ............. Specify the font path or url.
  -s, --fontSize ??? ......... Specify the font size. Default `72`.
  -o, --output ??? ........... Specify the output path. Default `logo.svg`
  -c, --config ??? ........... Specify the `.logorc` file.
  -O, --overwrite ............ Overwrite when a logo file exist. Default `true`.
  -k, --kerning .............. Take kerning information into account. Default `true`.
  -d, --divided .............. Generate individual path for every char. Default `false`.
  -V, --version .............. Print the current version.
  -h, --help ................. You're looking at it.
  -h, --help ??? ............. Show details for the specified command.

Examples:

  $ logo
  $ logo -Odo ./logo/logo.svg
  $ logo --config ./logo/.logorc
  $ logo --help
  $ logo --help font
  $ logo --help config
  $ logo --version

JavaScript API

var logo = require('logo.svg');
// generate the svg string, then you can use it in you code
var svg = logo.generate(options);

Options

font

The font's path or full url. If it's an url, we will load the font asynchronous then generate the logo.

If the path is relative, it is relative to the current work directory(process.cwd()).

If the path is a basename, such as fontName.ttf, we will fisrtly try to load it as a relative path, if that failed we will search it from the preset folder, and then search it from system and user fonts folders.

The preset folder is ./fonts/, contribute your fonts by pull request.

The logo text. Default is the name in package.json.

x

Horizontal position of the beginning of the text. (default: 0)

y

Vertical position of the baseline of the text. (default: 0)

fontSize

Size of the text. (default: 72)

spacing

The letter spacing. (default: 0)

kerning

If true takes kerning information into account. (default: true)

divided

If true generates individual path for every char. (default: false)

grouped

If true groups the individual <path> with <g></g> element. (default: false)

title

If specified will generate a <title> at the root of <svg>. (default: logo)

desc

If specified will generate a <desc> at the root of <svg>. (default: null)

Specify the padding of the <path> relative to the <svg>:

  • options.padding
  • options.paddingTop or options['padding-top']
  • options.paddingRight or options['padding-right']
  • options.paddingBottom or options['padding-bottom']
  • options.paddingLeft or options['padding-left']

The <svg>, <path> and <g> elements can be styled by any valid attributes.

The generated <svg> has the following default attributes:

{
    'version'    : '1.1',
    'xmlns'      : 'http://www.w3.org/2000/svg',
    'xmlns:xlink': 'http://www.w3.org/1999/xlink',
    'role'   : 'img',
    'width'  : width,
    'height' : height,
    'viewbox': [x, y, width, height].join(' ')
}

We can add/update/remove by options.svg:

options.svg = {
    'version': '',     // remove this attribute
    'role'   : 'logo', // update this attribute
    'fill'   : 'red'   // add some custiom styles
}

Note that the width, height and viewbox can't be specified.

Styling the <path> by options.path. If divided is true we can style the individual <path> element by options.path?, which ? is the index of each char in the logo:

// style for every path(s)
options.path  = {
    'fill': yellow
};

// style the first char
options.path0 = {
    'fill': '#FF0000',
    'stroke': '#000000'
};

As the same options.g specified the style of <g> element.

.logorc

All the options can be specified in the following files:

  • .logorc.js
  • .logorc.yaml
  • .logorc.yml
  • .logorc.json
  • .logorc
  • The logo section in package.json

We will try to load configuration from these files order by order, stop until any file load succeed.

Example for .logorc:

font: Origami-Mommy-Pixellated.ttf
fontSzie: 72
output: logo.svg
# style the logo
path:
  fill: '#6ccb99'

Example for package.json:

{
  "name": "module",
  "version": "1.0.0",

  "logo": {
    "font": "Origami-Mommy-Pixellated.ttf",
    "fontSzie": 72,
    "output": "logo.svg",
    "path": {
      "fill": "#6ccb99"
    }
  },

}

SVG does not work from README by design for security concerns

We have had to disable svg image rendering on GitHub.com due to potential cross site scripting vulnerabilities.

So, we can not embed by the raw url, rawgit.com solves this problem nicely. For each request, it retrieves the appropriate document from GitHub and, crucially, serves it with the correct Content-Type header.

Link to your logo.svg using the following pattern:

https://cdn.rawgit.com/<repo-owner>/<repo>/<branch>/path/to.svg

To ensure that the CDN always serves the version of the file you want, use a git tag or commit hash in the file's path instead of a branch name, and update the URL if you push a new version of the file.

So, instead of a URL like https://cdn.rawgit.com/user/repo/branch/file, use a URL like https://cdn.rawgit.com/user/repo/tag/file or https://cdn.rawgit.com/user/repo/commit/file.

The embed code looks like:

![logo.svg](https://cdn.rawgit.com/<repo-owner>/<repo>/<branch>/path/to.svg)

<img alt="logo.svg" width="500" src="https://cdn.rawgit.com/<repo-owner>/<repo>/<branch>/path/to.svg">

Demos

font: 'gubblebum-glocky.ttf'
logo: 'npm '
output: './demos/gubblebum-blocky/npm.svg'
path:
  fill: '#cb3837'

npm

logo: 'divided'
font: 'origami-mommy.ttf'
output: './demos/origami-mommy/divided.svg'
divided: true
path:
  fill: '#6af72e'
path1:
  fill: '#c6e03c'
path2:
  fill: '#fc428f'
path3:
  fill: '#cea2fd'
path4:
  fill: '#fb3f24'
path5:
  fill: '#3cc8f6'
path6:
  fill: '#ff3e74'

divided

logo: 'Blocked'
font: 'blocked.ttf'
output: './demos/blocked/blocked.svg'
path:
  fill: '#fc174f'

blocked

logo: 'Square'
font: 'mk-zodnig-square.ttf'
fontSize: 96
output: './demos/mk-zodnig-square/square.svg'
path:
  fill: '#fd742d'
#  stroke: '#fd742d'

square

logo: 'Gubblebum '
font: 'gubblebum.ttf'
output: './demos/gubblebum/gubblebum.svg'
spacing: 10
divided: true
path:
  fill: '#6af72e'
path0:
  fill: '#fc428f'

gubblebum

  • text2svg Convert text to svg path.
  • loadrc Load runtime configuration files for your module.

TODO

  • Support logo template.
  • What's your suggestion? Open an issue.

Contributing

Pull requests and stars are highly welcome.

For bugs and feature requests, please create an issue.

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文