条形码或称条码barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符。常见的条形码是由反射率相差很大的黑条(简称条)和白条(简称空)排成的平行线图案。条形码可以标出物品的生产国、制造厂家、商品名称、生产日期、图书分类号、邮件起止地点、类别、日期等信息,因而在商品流通、图书管理、邮政管理、银行系统等许多领域都得到了广泛的应用。

条形码分类

条形码按类型可分为:线性条形码矩阵(二维)条形码

code128编码

Code 128是ISO/IEC 15417:2007[1]定义的条形码规范。

Code 128条码可以对全部128个ASCII字符(包括数字、大小写字母、符号和控制符)进行编码。

code128码是广泛应用在企业内部管理、生产流程、物流控制系统方面的条码码制,由于其优良的特性在管理信息系统的设计中被广泛使用,CODE128码是应用最广泛的线性条形码制之一。

code128编码分类

  • code128 A字符集:包括大写字母、数字、常用标点符号和一些控制符。

  • code128B 字符集:包括大小写字母、数字、常用标点符号。

  • code128C 字符集: 为纯数字序列。

  • code128Auto:是将上述三种字符集最佳优化组合。

code128编码构成

一个Code 128条形码由六部分组成。

  1. 空白区域
  2. 起始标记
  3. 数据区
  4. 校验符
  5. 终止符
  6. 空白区域

code128编码表

ID Code128A Code128B Code128C BandCode 图案
0 SP SP 0 212222 11011001100
1 ! ! 1 222122 11001101100
2 2 222221 11001100110
3 # # 3 121223 10010011000
4 $ $ 4 121322 10010001100
5 % % 5 131222 10001001100
6 & & 6 122213 10011001000
7 7 122312 10011000100
8 ( ( 8 132212 10001100100
9 ) ) 9 221213 11001001000
10 * * 10 221312 11001000100
11 + + 11 231212 11000100100
12 , , 12 112232 10110011100
13 - - 13 122132 10011011100
14 . . 14 122231 10011001110
15 / / 15 113222 10111001100
16 0 0 16 123122 10011101100
17 1 1 17 123221 10011100110
18 2 2 18 223211 11001110010
19 3 3 19 221132 11001011100
20 4 4 20 221231 11001001110
21 5 5 21 213212 11011100100
22 6 6 22 223112 11001110100
23 7 7 23 312131 11101101110
24 8 8 24 311222 11101001100
25 9 9 25 321122 11100101100
26 : : 26 321221 11100100110
27 ; ; 27 312212 11101100100
28 < < 28 322112 11100110100
29 = = 29 322211 11100110010
30 > > 30 212123 11011011000
31 ? ? 31 212321 11011000110
32 @ @ 32 232121 11000110110
33 A A 33 111323 10100011000
34 B B 34 131123 10001011000
35 C C 35 131321 10001000110
36 D D 36 112313 10110001000
37 E E 37 132113 10001101000
38 F F 38 132311 10001100010
39 G G 39 211313 11010001000
40 H H 40 231113 11000101000
41 I I 41 231311 11000100010
42 J J 42 112133 10110111000
43 K K 43 112331 10110001110
44 L L 44 132131 10001101110
45 M M 45 113123 10111011000
46 N N 46 113321 10111000110
47 O O 47 133121 10001110110
48 P P 48 313121 11101110110
49 Q Q 49 211331 11010001110
50 R R 50 231131 11000101110
51 S S 51 213113 11011101000
52 T T 52 213311 11011100010
53 U U 53 213131 11011101110
54 V V 54 311123 11101011000
55 W W 55 311321 11101000110
56 X X 56 331121 11100010110
57 Y Y 57 312113 11101101000
58 Z Z 58 312311 11101100010
59 [ [ 59 332111 11100011010
60 \ \ 60 314111 11101111010
61 ] ] 61 221411 11001000010
62 ^ ^ 62 431111 11110001010
63 _ _ 63 111224 10100110000
64 NUL ` 64 111422 10100001100
65 SOH a 65 121124 10010110000
66 STX b 66 121421 10010000110
67 ETX c 67 141122 10000101100
68 EOT d 68 141221 10000100110
69 ENQ e 69 112214 10110010000
70 ACK f 70 112412 10110000100
71 BEL g 71 122114 10011010000
72 BS h 72 122411 10011000010
73 HT i 73 142112 10000110100
74 LF j 74 142211 10000110010
75 VT k 75 241211 11000010010
76 FF I 76 221114 11001010000
77 CR m 77 413111 11110111010
78 SO n 78 241112 11000010100
79 SI o 79 134111 10001111010
80 DLE p 80 111242 10100111100
81 DC1 q 81 121142 10010111100
82 DC2 r 82 121241 10010011110
83 DC3 s 83 114212 10111100100
84 DC4 t 84 124112 10011110100
85 NAK u 85 124211 10011110010
86 SYN v 86 411212 11110100100
87 ETB w 87 421112 11110010100
88 CAN x 88 421211 11110010010
89 EM y 89 212141 11011011110
90 SUB z 90 214121 11011110110
91 ESC { 91 412121 11110110110
92 FS | 92 111143 10101111000
93 GS } 93 111341 10100011110
94 RS ~ 94 131141 10001011110
95 US DEL 95 114113 10111101000
96 FNC3 FNC3 96 114311 10111100010
97 FNC2 FNC2 97 411113 11110101000
98 SHIFT SHIFT 98 411311 11110100010
99 CODEC CODEC 99 113141 10111011110
100 CODEB FNC4 CODEB 114131 10111101110
101 FNC4 CODEA CODEA 311141 11101011110
102 FNC1 FNC1 FNC1 411131 11110101110
103 StartA StartA StartA 211412 11010000100
104 StartB StartB StartB 211214 11010010000
105 StartC StartC StartC 211232 11010011100
106 Stop Stop Stop 2331112 1100011101011

code128检验位计算

(开始位对应的ID值 + 每位数据在整个数据中的位置×每位数据对应的ID值)% 103

Code128编码示例

PZ1704946715 为例,开始为code128A,开始位对应的ID为103,第1位数据P对应的ID为48,第2位数据Z对应的ID为58,依此类推,可以计算。

检验位 = (103 + 1 * 48 + 2 * 58 + 3 * 17 + 4 * 23 + 5 * 16 + 6 * 20 +7 * 25 + 8 * 20 + 9 * 22 + 10 * 23 + 11 * 17 + 12 * 21) % 103 = 61​

即检验位的ID为61。

对照编码表,PZ1704946715 编码表示为:开始位Start Code A(11010000100)+ 数据位[P(11101110110)+ Z(11101100010)+1(10011100110)+ 7(11101101110)+ 0(10011101100)+ 4(11001001110)+ 9(11100101100)+ 4(11001001110)+ 6(11001110100)+ 7(11101101110)+ 1(10011100110)+ 5(11011100100)]+ 检验位61(11001000010)+ 结束位Stop(1100011101011)

若要打印,只需将1用黑色线标出,0用白色线标出,就完成一个简单的条形码生成。

该文章是对youtube-dl 项目README.md文件的翻译,项目地址:https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme

当前版本:v2019.03.18


youtube-dl - 从youtube.com或其他视频平台下载视频

安装

立即为所有UNIX用户安装 (如Linux, macOS, 等),输入:

1
2
sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

如果你没有curl工具, 你也可以使用相近的wget工具:

1
2
sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

Windows用户可以 下载exe文件 并且放在除了%SYSTEMROOT%\System32以外任何的PATH 位置 (例如:不要 放在 C:\Windows\System32).

你也可以通过pip安装:

1
sudo -H pip install --upgrade youtube-dl

如果你早已安装youtube-dl,该命令行将会更新它。想获取更多信息,请参阅 pypi page

macOS用户可以通过Homebrew工具来安装youtube-dl:

1
brew install youtube-dl

或则使用 MacPorts工具:

1
sudo port install youtube-dl

此外,参考 开发者向导 来查看如何使用git仓库。 想获取包括PGP签名的更多选项,请参阅youtube-dl 下载界面

描述

youtube-dl是一款命令行工具,可以从YouTube.com和一些其他站点下载视频。它依赖于Python解释器,解释器版本要求为 2.6, 2.7, 或者 3.2+,并不限制于特定平台。它应该可以运行在类Unix,Windows和macOS平台上。其被发布于公共域, 意味着你可以修改、重新分发、或凭个人意愿使用它。

1
youtube-dl [OPTIONS] URL [URL...]

选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-h, --help						打印帮助文档并退出
--version 打印程序版本信息并退出
-U, --update 更新程序至最新版本,需保证拥有足够权限(如需可使用sudo命令)
-i, --ignore-errors 当下载错误时继续,例如在播放列表跳过不可获取视频
--abort-on-error 当下载错误时停止下载其他视频(例如在播放列表和命令行)
--dump-user-agent 展示当前浏览器标识
--list-extractors 列出所有的提取器
--extractor-descriptions 输出所有支持的提取器描述
--force-generic-extractor 强制使用通用提取器
--default-search PREFIX 使用前缀补全不完整的URLs。例如“gvsearch2:”利用youtube-dl从google视频中下载两个有关“大苹果”的视频,使用"auto"参数让youtube-dl自行猜一个(猜测时,"auto_warning"将会抛出)。"error"参数就会抛出错误。默认值"fixup_error"会修复不完整URLs,如果不是搜索相关就无法实现,会抛出错误。
--ignore-config 当使用全局配置文件/etc/youtube-dl.conf时,不再读取用户的配置文件~/.config/youtube-dl/config(Windows下为%APPDATA%/youtube-dl/config.txt)
--config-location PATH 配置文件的配置,既可以是配置文件的路径或包含其的目录
--flat-playlist 仅列出视频列表而不下载
--mark-watched 标记看过此视频(仅对YouTube)
--no-mark-watched 不标记看过此视频(仅对YouTube)
--no-color 对屏幕输出结果不上色

网络选项:

1
2
3
4
5
--proxy URL						使用HTTP/HTTPS/SOCKS代理。需指定一个具体的协议,例如:socks5://127.0.0.1:1080/。传入空字段(--proxy "")将会直连
--socket-timeout SECONDS 放弃连接前的等待时间,秒为单位
--source-address IP 绑定客户端的IP地址
-4, --force-ipv4 所有连接强制走IPv4协议
-6, --force-ipv6 所有连接强制走IPv6协议

地区限制:

1
2
3
4
5
--geo-verification-proxy URL	在一些地区限制网址使用代理IP地址。由--proxy指定的默认代理(如果该选项不存在,则为none)用于实际下载。
--geo-bypass 通过伪装HTTP头:X-Forwarded-For 来绕过地区限制
--no-geo-bypass 不用伪装HTTP头:X-Forwarded-For 来绕过地区限制
--geo-bypass-country CODE 利用提供具体的双字母ISO 3166-2国别码强制绕过地区限制
--geo-bypass-ip-block IP_BLOCK 使用CIDR表示法中明确提供的IP块强制绕过地理限制

视频选择:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
--playlist-start NUMBER			播放列表中从第几个开始下载(默认是1)
--playlist-end NUMBER 播放列表中到第几个结束下载(默认最后一个)
--playlist-items ITEM_SPEC 指定列表中要下载的视频项目编号。如:"--playlist-items 1,2,5,8""--playlist-items 1-3,7,10-13"
--match-title REGEX 下载标题匹配的视频(可用正则表达式或区分大小写的子字符串)
--reject-title REGEX 跳过下载标题匹配的视频(可用正则表达式或区分大小写的子字符串)
--max-downloads NUMBER 下载NUMBER个文件后中止
--min-filesize SIZE 不下载小于SIZE的视频(例如:50k或44.6m)
--max-filesize SIZE 不下载大于SIZE的视频(例如:50k或44.6m)
--date DATE 仅下载指定上传日期的视频
--datebefore DATE 仅下载指定上传日期或之前的视频
--dateafter DATE 仅下载指定上传日期或之后的视频
--min-views COUNT 不下载观看次数小于COUNT的视频
--max-views COUNT 不下载观看次数大于COUNT的视频
--match-filter FILTER 通用视频过滤器。可指定任何键(有关可用key列表,请参阅“OUTPUT TEMPLATE”)!key检查密钥是否不存在,key>NUMBER(如“comment_count> 12”,也适用于> =,<,<=,!=,=) 比较一个数字,key ='LITERAL'(比如“uploader ='Mike Smith',也适用于!=)来匹配字符串文字可用&实现多个匹配。 除非您在参数后加问号(?),否则将排除未知的值。例如,要仅匹配已liked超过100次并且disliked不到50次的视频(或者在给定视频中不可用的不喜欢功能)并且有视频描述,请使用--match-filter "like_count > 100&dislike_count <? 50 & description"
--no-playlist 如果URL指向视频和播放列表,则仅下载视频
--yes-playlist 如果URL指向视频和播放列表,则仅下载播放列表
--age-limit YEARS 仅下载适合特定年龄的视频
--download-archive FILE 仅下载存档文件中未列出的视频。记录下载所有视频的ID。
--include-ads 下载时同时下载广告(实验性功能)

下载选项:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-r, --limit-rate RATE			最大下载速率(bps)(例如 50K 或 4.2M)
-R, --retries RETRIES 重试次数。(默认10,可选 "infinite"
--fragment-retries RETRIES 片段重试次数(默认10),可选 "infinite")(DASH, hlsnative and ISM)
--skip-unavailable-fragments 跳过不可用片段 (DASH, hlsnative and ISM)
--abort-on-unavailable-fragment 当片段不可获取时,中断下载
--keep-fragments 下载完成后,将下载的片段保存在磁盘上; 片段默认被删除
--buffer-size SIZE 下载缓存大小(例如 1024 或 16K)(默认 1024)
--no-resize-buffer 不自动调整缓存大小。默认情况下,缓存大小会基于初始大小自动调整
--http-chunk-size SIZE 基于块的HTTP下载的块的大小(例如10485760或10M)(默认为禁用)。 可能有助于绕过网络服务器强加的带宽限制(实验性功能)
--playlist-reverse 逆序下载视频列表
--playlist-random 随机顺序下载视频列表
--xattr-set-filesize 设定xattribute ytdl文件大小
--hls-prefer-native 使用原生HLS代替ffmpeg进行下载
--hls-prefer-ffmpeg 使用ffmpeg代替原生HLS进行下载
--hls-use-mpegts 使用mpegts容器获取HLS视频,允许在下载时播放视频(某些播放器可能无法播放)
--external-downloader COMMAND 使用指定的外部下载程序。目前支持aria2c,avconv,axel,curl,ffmpeg,httpie,wget
--external-downloader-args ARGS 为外部下载器指定参数

文件系统选项:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-a, --batch-file FILE            File containing URLs to download ('-' for
stdin), one URL per line. Lines starting
with '#', ';' or ']' are considered as
comments and ignored.
--id Use only video ID in file name
-o, --output TEMPLATE Output filename template, see the "OUTPUT
TEMPLATE" for all the info
--autonumber-start NUMBER Specify the start value for %(autonumber)s
(default is 1)
--restrict-filenames Restrict filenames to only ASCII
characters, and avoid "&" and spaces in
filenames
-w, --no-overwrites Do not overwrite files
-c, --continue Force resume of partially downloaded files.
By default, youtube-dl will resume
downloads if possible.
--no-continue Do not resume partially downloaded files
(restart from beginning)
--no-part Do not use .part files - write directly
into output file
--no-mtime Do not use the Last-modified header to set
the file modification time
--write-description Write video description to a .description
file
--write-info-json Write video metadata to a .info.json file
--write-annotations Write video annotations to a
.annotations.xml file
--load-info-json FILE JSON file containing the video information
(created with the "--write-info-json"
option)
--cookies FILE File to read cookies from and dump cookie
jar in
--cache-dir DIR Location in the filesystem where youtube-dl
can store some downloaded information
permanently. By default
$XDG_CACHE_HOME/youtube-dl or
~/.cache/youtube-dl . At the moment, only
YouTube player files (for videos with
obfuscated signatures) are cached, but that
may change.
--no-cache-dir Disable filesystem caching
--rm-cache-dir Delete all filesystem cache files

Thumbnail images:

1
2
3
4
--write-thumbnail                Write thumbnail image to disk
--write-all-thumbnails Write all thumbnail image formats to disk
--list-thumbnails Simulate and list all available thumbnail
formats

Verbosity / Simulation Options:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
-q, --quiet                      Activate quiet mode
--no-warnings Ignore warnings
-s, --simulate Do not download the video and do not write
anything to disk
--skip-download Do not download the video
-g, --get-url Simulate, quiet but print URL
-e, --get-title Simulate, quiet but print title
--get-id Simulate, quiet but print id
--get-thumbnail Simulate, quiet but print thumbnail URL
--get-description Simulate, quiet but print video description
--get-duration Simulate, quiet but print video length
--get-filename Simulate, quiet but print output filename
--get-format Simulate, quiet but print output format
-j, --dump-json Simulate, quiet but print JSON information.
See the "OUTPUT TEMPLATE" for a description
of available keys.
-J, --dump-single-json Simulate, quiet but print JSON information
for each command-line argument. If the URL
refers to a playlist, dump the whole
playlist information in a single line.
--print-json Be quiet and print the video information as
JSON (video is still being downloaded).
--newline Output progress bar as new lines
--no-progress Do not print progress bar
--console-title Display progress in console titlebar
-v, --verbose Print various debugging information
--dump-pages Print downloaded pages encoded using base64
to debug problems (very verbose)
--write-pages Write downloaded intermediary pages to
files in the current directory to debug
problems
--print-traffic Display sent and read HTTP traffic
-C, --call-home Contact the youtube-dl server for debugging
--no-call-home Do NOT contact the youtube-dl server for
debugging

Workarounds:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
--encoding ENCODING              Force the specified encoding (experimental)
--no-check-certificate Suppress HTTPS certificate validation
--prefer-insecure Use an unencrypted connection to retrieve
information about the video. (Currently
supported only for YouTube)
--user-agent UA Specify a custom user agent
--referer URL Specify a custom referer, use if the video
access is restricted to one domain
--add-header FIELD:VALUE Specify a custom HTTP header and its value,
separated by a colon ':'. You can use this
option multiple times
--bidi-workaround Work around terminals that lack
bidirectional text support. Requires bidiv
or fribidi executable in PATH
--sleep-interval SECONDS Number of seconds to sleep before each
download when used alone or a lower bound
of a range for randomized sleep before each
download (minimum possible number of
seconds to sleep) when used along with
--max-sleep-interval.
--max-sleep-interval SECONDS Upper bound of a range for randomized sleep
before each download (maximum possible
number of seconds to sleep). Must only be
used along with --min-sleep-interval.

Video Format Options:

1
2
3
4
5
6
7
8
9
10
11
12
13
-f, --format FORMAT              Video format code, see the "FORMAT
SELECTION" for all the info
--all-formats Download all available video formats
--prefer-free-formats Prefer free video formats unless a specific
one is requested
-F, --list-formats List all available formats of requested
videos
--youtube-skip-dash-manifest Do not download the DASH manifests and
related data on YouTube videos
--merge-output-format FORMAT If a merge is required (e.g.
bestvideo+bestaudio), output to given
container format. One of mkv, mp4, ogg,
webm, flv. Ignored if no merge is required

Subtitle Options:

1
2
3
4
5
6
7
8
9
10
11
12
--write-sub                      Write subtitle file
--write-auto-sub Write automatically generated subtitle file
(YouTube only)
--all-subs Download all the available subtitles of the
video
--list-subs List all available subtitles for the video
--sub-format FORMAT Subtitle format, accepts formats
preference, for example: "srt" or
"ass/srt/best"
--sub-lang LANGS Languages of the subtitles to download
(optional) separated by commas, use --list-
subs for available language tags

Authentication Options:

1
2
3
4
5
6
-u, --username USERNAME          Login with this account ID
-p, --password PASSWORD Account password. If this option is left
out, youtube-dl will ask interactively.
-2, --twofactor TWOFACTOR Two-factor authentication code
-n, --netrc Use .netrc authentication data
--video-password PASSWORD Video password (vimeo, smotri, youku)

Adobe Pass Options:

1
2
3
4
5
6
7
8
9
--ap-mso MSO                     Adobe Pass multiple-system operator (TV
provider) identifier, use --ap-list-mso for
a list of available MSOs
--ap-username USERNAME Multiple-system operator account login
--ap-password PASSWORD Multiple-system operator account password.
If this option is left out, youtube-dl will
ask interactively.
--ap-list-mso List all supported multiple-system
operators

Post-processing Options:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-x, --extract-audio              Convert video files to audio-only files
(requires ffmpeg or avconv and ffprobe or
avprobe)
--audio-format FORMAT Specify audio format: "best", "aac",
"flac", "mp3", "m4a", "opus", "vorbis", or
"wav"; "best" by default; No effect without
-x
--audio-quality QUALITY Specify ffmpeg/avconv audio quality, insert
a value between 0 (better) and 9 (worse)
for VBR or a specific bitrate like 128K
(default 5)
--recode-video FORMAT Encode the video to another format if
necessary (currently supported:
mp4|flv|ogg|webm|mkv|avi)
--postprocessor-args ARGS Give these arguments to the postprocessor
-k, --keep-video Keep the video file on disk after the post-
processing; the video is erased by default
--no-post-overwrites Do not overwrite post-processed files; the
post-processed files are overwritten by
default
--embed-subs Embed subtitles in the video (only for mp4,
webm and mkv videos)
--embed-thumbnail Embed thumbnail in the audio as cover art
--add-metadata Write metadata to the video file
--metadata-from-title FORMAT Parse additional metadata like song title /
artist from the video title. The format
syntax is the same as --output. Regular
expression with named capture groups may
also be used. The parsed parameters replace
existing values. Example: --metadata-from-
title "%(artist)s - %(title)s" matches a
title like "Coldplay - Paradise". Example
(regex): --metadata-from-title
"(?P<artist>.+?) - (?P<title>.+)"
--xattrs Write metadata to the video file's xattrs
(using dublin core and xdg standards)
--fixup POLICY Automatically correct known faults of the
file. One of never (do nothing), warn (only
emit a warning), detect_or_warn (the
default; fix file if we can, warn
otherwise)
--prefer-avconv Prefer avconv over ffmpeg for running the
postprocessors
--prefer-ffmpeg Prefer ffmpeg over avconv for running the
postprocessors (default)
--ffmpeg-location PATH Location of the ffmpeg/avconv binary;
either the path to the binary or its
containing directory.
--exec CMD Execute a command on the file after
downloading, similar to find's -exec
syntax. Example: --exec 'adb push {}
/sdcard/Music/ && rm {}'
--convert-subs FORMAT Convert the subtitles to other format
(currently supported: srt|ass|vtt|lrc)

背景

个人以前博客常挂在自建的基于dockerWordPress平台,但往日学艺不精,对docker操作陌生,都是基于别人的模板快速搭建;尽近两年来,经历了多次迁移:

  • 腾讯云(centOS) → 阿里云(ubuntu) → DigitalOcean(ubuntu)

同时也经过了多次的版本升级,且前期多是在wordpress内置的编辑器中编写,也尝试过百度UEditor编辑器

,最终转到MarkDown编辑器。除此外,图床也一变再变,过程中多次忘记备份,导致存在一些图片缺失。

回想写博客的本质,是为了记录心路,学习知识。实在不应该放过多时间在博客建设本身😢。

思前想后,还是准备把博客落脚在GitHub Page,不用去考虑数据库、cdn等,仅采用静态页面,一篇文章也为一份md文件,图床部分也不去用七牛等服务商,就是oneDrive的分享,简单直接。写博客也应该像提交代码一样,commit + push😉。

大致步骤如下:

GitHub建立固定格式仓库

登录GitHub,新建一个仓库,在Repository name中输入新建仓库的名称,我们现在是要搭建自己的个人博客,Repository name是有固定格式的:name.github.io,其中name可以随便填,一般是用自己的名字,点击Create Repository。

配置Git

安装Git

Git下载地址,选择适合版本,默认安装即可,安装后git相关命令会自动添加到系统path。可通过:

1
git --version

来确认。

配置Git

为了把本地的仓库中的内容传输到GitHub上,需要配置ssh key,无论是上传自己的博客还是上传其他的仓库都需要连接Github,ssh key是一个token,作用是身份验证。 为了在本地创建ssh key,打开Git Bash,输入命令:

1
ssh-keygen -t rsa -C "email"  # email是我们在注册Github时使用的邮箱

输入上面的命令后按Enter键,Git Bash会提示:

1
Enter file in which to save the key (/c/Users/sun/.ssh/id_rsa):_

直接按Enter,Git Bash会在默认路径C:.ssh下生成几个文件。

然后Git Bash又给出提示:

1
Enter passphrase <empty for no passphrase>:_

这是在提示我们输入密码,直接回车表示不设置密码;此处我不设置密码,然后Git Bash要求我们重复密码,也直接回车,然后就会提示ssh key已经生成。

  1. 点击Settings;

  2. 在页面左侧找到Deploy keys并点击;

  3. 点击右侧的Add deploy key按钮,title随意填,Key填写ssh key文件中复制的key(包括ssh-ras头);

  4. 点击Add Key,保存ssh key。

我们需在本地验证ssh key设置是否成功,打开cmd,输入命令:

1
ssh -T git@github.com

若看到

1
You’ve successfully authenticated, but GitHub does not provide shell access

表示当前已经成功地连接上了自己的GitHub账户

接下来,设置一下自己的用户名和邮箱

1
2
git config --global user.name "my_github_name"
git config --global user.email "my_github_email"

至此,我们已经成功地将个人电脑和Github账号连接。

安装node.js 和 hexo

安装node.js

node.js下载地址

按照需要选择不同的版本,下载到本地之后,直接双击安装,一路默认即可,node.js安装后,会自动配置环境变量,打开windows的控制台,输入命令:

1
node -v

安装Hexo

hexo项目须在电脑的磁盘里新建一个空文件夹,在我的电脑上是*C:_next*,用于存放本地仓库,和Github上的xxxxx.github.io是对应的,下面以命令行为例,完成Hexo安装

1
2
3
mkdir C:\Users\smile\hexo_next   # 新建文件夹
cd C:\Users\smile\hexo_next
npm install hexo -g # 安装Hexo,-g代表全局安装

安装耗时较长,最终可通过

1
hexo -v

检测安装

搭建本地测试环境

初始化*C:_next*这个文件夹,打开Git Bash进入此目录,输入命令:

1
2
3
4
hexo init
npm install # 安装Hexo所需要的组件
hexo g # 产生webapp文件
hexo s # 开启服务器

此时控制台提示:

1
2
3
4
5
6
7
8
9
INFO  Start processing
WARN ===============================================================
WARN ========================= ATTENTION! ==========================
WARN ===============================================================
WARN NexT repository is moving here: https://github.com/theme-next
WARN ===============================================================
WARN It's rebase to v6.0.0 and future maintenance will resume there
WARN ===============================================================
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.

表明启动成功

使用next设计个性化博客

将Hexo的主题切换为NexT

进入到*C:_next*文件夹,打开cmd

1
git clone https://github.com/theme-next/hexo-theme-next themes/next

打开C:_next\_config.yml

把theme: lansscape改为theme: next

切换Next主题

进入C:_next,打开NexT的配置文件_config.yml,选择自己喜欢的主题样式,选择哪个样式就需要把主题前面的#去掉

设置动态背景

在*C:_next\_config.yml*中,canvas_nest设置成ture,并且可选多种动态背景

取消侧边栏目录的自动编号

在*C:_next\_config.yml*中,修改toc下number属性为false

在右上角或者左上角实现fork me on github

GitHub RibbonsGitHub Corners选择自己喜欢的挂饰,拷贝方框内的代码

将复制的代码放到C:_next_layout.swig文件中,放在

1
<div class="headband"></div>

后面,如下图

实现文章字数统计和阅读时长功能

1
npm install hexo-wordcount --save

编辑*C:_next\_config.yml*,找到post_wordcount,将所有的false都改为true:

Hexo博客添加站内搜索

需要安装 hexo-generator-search,输入命令:

1
npm install hexo-generator-search --save

安装 hexo-generator-searchdb,输入命令:

1
npm install hexo-generator-searchdb --save

编辑*C:_next\_config.yml*,找到Local search,做如下设置:

效果如下:

连接Hexo和Github Pages及部署博客

接下来就是将Hexo与GitHub Pages连接起来 打开*C:_next\_config.yml*文件,找到deploy字段,改为如下内容

1
2
3
4
deploy:
type: git
repository: git@github.com:user_name/respname.github.io.git
branch: master

填写GitHub的用户名 和 博客仓库名,如下图所示

在产生webapp应用和部署到GitHub之前,需要安装一个扩展插件,在C:_next中打开cmd,输入命令:

1
npm install hexo-deployer-git --save

使用命令:

1
hexo clean & hexo d -g  # hexo g 生成webapp应用  # hexo d 部署

就可以发布到GitHub上啦!😉

第十九周

课程 日期 时间
微机原理 1月8号 13:30 - 15:10
计算机网络技术 1月9号 13:30 - 15:10
数字信号处理 1月10号 8:00 - 9:40
毛概 1月10号 10:20 - 12:00
通信原理 1月11号 15:50 - 17:30
0%