jekyll-page-boilerplate 4.1.1 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jekyll_page_boilerplate/list.rb +1 -4
- data/lib/jekyll_page_boilerplate/msg/description.md +5 -2
- data/lib/jekyll_page_boilerplate/msg/gem_description.md +15 -0
- data/lib/jekyll_page_boilerplate/page.rb +41 -67
- data/lib/jekyll_page_boilerplate/tags.rb +70 -0
- data/lib/jekyll_page_boilerplate/version.rb +1 -1
- data/lib/jekyll_page_boilerplate.rb +1 -0
- data/lib/jekyll_page_boilerplate_cli.rb +4 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65d5d4ea29334a96097f61f901251bd077dd288ef96db98316e79c289db435ea
|
4
|
+
data.tar.gz: 44365677835697d6b07f636a14e81a96595be48274d0e3a828c9b09499282d89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71b662bc22160d2a1550eac1beedb5ebebca1484765d1e3b18062f863a7948f8b3b7d7773c8caf6a639a8937f9609e01cfed01dc1643d0e0bc1a9c3195b7c0a2
|
7
|
+
data.tar.gz: fd59775cb1917f121ba79861a9b5aad461b0928d482e1af2a59a7b8236732b2ce397ed3594491d4372516a1611213aa14153847ae45f88db3b1340051743f59f
|
@@ -5,7 +5,10 @@ A boilerplate is a markdown file you place under the `_boilerplates` folder to g
|
|
5
5
|
---
|
6
6
|
_boilerplate: # boilerplate settings
|
7
7
|
path: _posts # the path to create the new page under.
|
8
|
-
timestamp: true # when true new post/pages will include the date in the filename.
|
8
|
+
timestamp: true # when true new post/pages will include the date in the filename.
|
9
|
+
slug: '{{ title }}-{{ num }}'
|
10
|
+
# slug is a template for the filename, it cant take the same tags as everything else.
|
11
|
+
num: 0
|
9
12
|
title: {{ boilerplate.title }} # tags like this will be replaced
|
10
13
|
layout: post # everthing else will be copied to the new post.
|
11
14
|
author: John Doe
|
@@ -24,6 +27,6 @@ Available Tags `{{ boilerplate.xxx }}`:
|
|
24
27
|
- `.title`, `.name`
|
25
28
|
- `.path`, `.file`, `.suffix`
|
26
29
|
- `.time`, `.date`, `.timestamp`
|
27
|
-
- `.
|
30
|
+
- `.random`
|
28
31
|
- Custom tags you provide in the command `bplate post custom=1`
|
29
32
|
- And anything you put under the `_boilerplate:` header
|
@@ -0,0 +1,15 @@
|
|
1
|
+
A boilerplate is a markdown file you place under the `_boilerplates/` folder to generate new pages for jekyll.
|
2
|
+
|
3
|
+
|
4
|
+
It can automatically timestamp and title new pages.
|
5
|
+
|
6
|
+
|
7
|
+
It will also replacing any `{{ boilerplate.xxx }}` tags with content. Available tags include `.time, .title, .date, .random`.
|
8
|
+
|
9
|
+
|
10
|
+
You can also provide custom tags with `boilerplate post nav_order=1` > `{{ boilerplate.nav_order }}`.
|
11
|
+
|
12
|
+
|
13
|
+
In the boilerplate header you can specify options like the path to generate pages under and if filenames should be timestamped. `_boilerplate: > path: '_posts/'`
|
14
|
+
|
15
|
+
|
@@ -2,28 +2,26 @@
|
|
2
2
|
require 'yaml'
|
3
3
|
require "stringex"
|
4
4
|
require 'securerandom'
|
5
|
+
require 'fileutils'
|
5
6
|
|
6
7
|
class JekyllPageBoilerplate::Page
|
7
8
|
|
8
9
|
BOILERPLATES_PATH = '_boilerplates'
|
9
|
-
FILE_DATE_FORMATE = '%Y-%m-%d'
|
10
10
|
READ_CONFIG_REGEX = /[\r\n\s]{0,}^_boilerplate:(\s*^[\t ]{1,2}.+$)+[\r\s\n]{0,}(?![^\r\s\n])/
|
11
11
|
READ_FILE_REGEX = /^-{3}\s*^(?<head>[\s\S]*)^-{3}\s^(?<body>[\s\S]*)/
|
12
|
-
TAGS_REGEX =
|
12
|
+
TAGS_REGEX = /\{{2}\s{0,}boilerplate\.([^\{\}\.\s]+)\s{0,}\}{2}/
|
13
13
|
|
14
|
-
attr_reader :config
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
attr_reader :tags
|
16
|
+
|
17
|
+
def self.run boilerplate, *options
|
18
|
+
page = self.new(boilerplate, *options)
|
18
19
|
page.create
|
19
|
-
return "Created
|
20
|
+
return "Created "+ File.join(page.tags['path'], page.tags['file'])
|
20
21
|
end
|
21
22
|
|
22
|
-
def initialize boilerplate, options
|
23
|
-
|
24
|
-
options.transform_keys!(&:to_s)
|
25
|
-
plate_path = get_boilerplate_path(boilerplate).to_s
|
26
|
-
|
23
|
+
def initialize boilerplate, *options, **params
|
24
|
+
plate_path = get_boilerplate_path(boilerplate)
|
27
25
|
abort_unless_file_exists( plate_path )
|
28
26
|
|
29
27
|
parsed_file = {}
|
@@ -31,31 +29,45 @@ class JekyllPageBoilerplate::Page
|
|
31
29
|
parsed_file = file.read.match(READ_FILE_REGEX).named_captures
|
32
30
|
end
|
33
31
|
|
34
|
-
@
|
35
|
-
|
36
|
-
|
32
|
+
@tags = JekyllPageBoilerplate::Tags.new(
|
33
|
+
defaults(plate_path),
|
34
|
+
get_header_config(parsed_file['head']),
|
35
|
+
*options,
|
36
|
+
params
|
37
|
+
)
|
38
|
+
@tags[:file] = '{{ date }}-{{ slug }}{{ suffix }}' if @tags.timestamp
|
39
|
+
@tags.fill(:slug, :file, :path, safe: true)
|
40
|
+
|
37
41
|
@head = get_head(parsed_file['head'])
|
38
|
-
@body =
|
42
|
+
@body = parsed_file['body']
|
39
43
|
end
|
40
44
|
|
41
45
|
def create
|
42
|
-
@
|
43
|
-
@config['date'] ||= Time.now.strftime(FILE_DATE_FORMATE)
|
44
|
-
|
45
|
-
abort_unless_file_exists(@config['path'])
|
46
|
-
|
47
|
-
@config['file'] ||= get_new_page_filename(@config['title'] || @config['name'])
|
46
|
+
FileUtils.mkdir_p(@tags.path)
|
48
47
|
|
49
48
|
scan_template :@body
|
50
49
|
scan_template :@head
|
51
50
|
|
52
|
-
create_new_page
|
51
|
+
create_new_page
|
53
52
|
end
|
54
|
-
|
53
|
+
|
55
54
|
private
|
56
55
|
|
57
|
-
def
|
58
|
-
|
56
|
+
def defaults(plate_path, timestamp: false)
|
57
|
+
basename = File.basename(plate_path, '.*')
|
58
|
+
{
|
59
|
+
suffix: plate_path[/\.\w+$/],
|
60
|
+
name: plate_path[/.*(?=\.)/] || plate_path,
|
61
|
+
basename: basename,
|
62
|
+
title: basename,
|
63
|
+
slug: '{{ title }}',
|
64
|
+
path: '_posts/',
|
65
|
+
file: '{{ slug }}{{ suffix }}',
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_new_page
|
70
|
+
new_file_path = File.join( @tags.path, @tags.file )
|
59
71
|
|
60
72
|
abort_if_file_exists(new_file_path)
|
61
73
|
|
@@ -69,35 +81,12 @@ class JekyllPageBoilerplate::Page
|
|
69
81
|
end
|
70
82
|
|
71
83
|
def scan_template var
|
72
|
-
instance_variable_get(var).scan(TAGS_REGEX).uniq.each do |tag
|
73
|
-
instance_variable_get(var).gsub! /\{{2}\s{0,}boilerplate\.#{
|
84
|
+
instance_variable_get(var).scan(TAGS_REGEX).flatten.uniq.each do |tag|
|
85
|
+
instance_variable_get(var).gsub! /\{{2}\s{0,}boilerplate\.#{tag}\s{0,}\}{2}/, @tags[tag].to_s
|
74
86
|
end
|
75
87
|
end
|
76
88
|
|
77
|
-
def
|
78
|
-
return @config[key] if @config[key]
|
79
|
-
key = key.split('=')
|
80
|
-
return Tag.send(key[0].to_sym, *key[1]&.split(','))
|
81
|
-
end
|
82
|
-
|
83
|
-
class Tag
|
84
|
-
class << self
|
85
|
-
def method_missing *args
|
86
|
-
''
|
87
|
-
end
|
88
|
-
|
89
|
-
def random_url length = nil
|
90
|
-
length && length = length.to_i
|
91
|
-
SecureRandom.urlsafe_base64(length)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def get_body markdown
|
97
|
-
return markdown
|
98
|
-
end
|
99
|
-
|
100
|
-
def get_config head
|
89
|
+
def get_header_config head
|
101
90
|
return YAML.load(head.match(READ_CONFIG_REGEX).to_s)['_boilerplate']
|
102
91
|
end
|
103
92
|
|
@@ -105,25 +94,10 @@ class JekyllPageBoilerplate::Page
|
|
105
94
|
return head.gsub( READ_CONFIG_REGEX, '')
|
106
95
|
end
|
107
96
|
|
108
|
-
|
109
97
|
def get_boilerplate_path plate_name
|
110
|
-
return Dir.glob(
|
111
|
-
"#{File.join(BOILERPLATES_PATH, plate_name)}*"
|
112
|
-
).first
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
def get_new_page_filename title
|
117
|
-
title = title.to_url
|
118
|
-
title = "#{title}#{@config['suffix']}"
|
119
|
-
if @config['timestamp']
|
120
|
-
title = "#{@config['date']}-#{title}"
|
121
|
-
end
|
122
|
-
return title
|
98
|
+
return Dir.glob( "#{File.join(BOILERPLATES_PATH, plate_name)}*" ).first.to_s
|
123
99
|
end
|
124
100
|
|
125
|
-
|
126
|
-
|
127
101
|
def abort_if_file_exists(file_path)
|
128
102
|
if File.exist?(file_path)
|
129
103
|
raise "#{file_path} already exists!"
|
@@ -0,0 +1,70 @@
|
|
1
|
+
|
2
|
+
class JekyllPageBoilerplate::Tags
|
3
|
+
|
4
|
+
FILE_DATE_FORMATE = '%Y-%m-%d'
|
5
|
+
FILL_SCAN = /\{{2}\s{0,}([^\{\}\.\s]+)\s{0,}\}{2}/
|
6
|
+
|
7
|
+
def self.[] *args
|
8
|
+
self.new *args
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize *args, **params
|
12
|
+
@tags = {}
|
13
|
+
add(*args, params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def []= key, val
|
17
|
+
@tags[key.to_s] = val
|
18
|
+
end
|
19
|
+
|
20
|
+
def add *args, **params
|
21
|
+
args.map! {|h| h.transform_keys(&:to_s).compact }
|
22
|
+
params.transform_keys!(&:to_s).compact!
|
23
|
+
@tags.merge!(*args, params)
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def [] key
|
28
|
+
key = key.to_s
|
29
|
+
@tags[key] ||= fetch(*key.split(/\s*=\s*|\s*,\s*/))
|
30
|
+
end
|
31
|
+
|
32
|
+
def fill *keys, safe: false
|
33
|
+
keys.map!(&:to_s)
|
34
|
+
keys.each do |k|
|
35
|
+
@tags[k].scan(FILL_SCAN).flatten.uniq.each do |tag|
|
36
|
+
@tags[k].gsub! /\{{2}\s{0,}#{tag.to_s}\s{0,}\}{2}/, self[tag].to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
if safe
|
40
|
+
keys.each do |k|
|
41
|
+
@tags[k] = safe(k)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def safe key
|
48
|
+
self[key].to_s.downcase.gsub(/[^0-9a-z\.\-\/]+/, '-')
|
49
|
+
end
|
50
|
+
|
51
|
+
def fetch key, *params
|
52
|
+
case key
|
53
|
+
when 'safe'
|
54
|
+
safe(params.join(','))
|
55
|
+
when 'time'
|
56
|
+
Time.now.to_s
|
57
|
+
when 'date'
|
58
|
+
Time.now.strftime(FILE_DATE_FORMATE)
|
59
|
+
when 'random'
|
60
|
+
SecureRandom.hex(*params.map(&:to_i))
|
61
|
+
else
|
62
|
+
''
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def method_missing key
|
68
|
+
@tags[key.to_s]
|
69
|
+
end
|
70
|
+
end
|
@@ -10,15 +10,17 @@ class JekyllPageBoilerplate::Application < Bales::Application
|
|
10
10
|
description: "`path/<title>.md`"
|
11
11
|
option :path, type: String, long_form: '--path', short_form: '-p',
|
12
12
|
description: "`<path>/title.md`"
|
13
|
+
option :slug, type: String, long_form: '--slug', short_form: '-u',
|
14
|
+
description: "`path/<slug-template>.md` `{{title}}-{{date}}`"
|
13
15
|
option :timestamp, type: TrueClass, long_form: '--timestamp', short_form: '-s',
|
14
16
|
description: "`path/<time.now>-title.md`"
|
15
17
|
option :suffix, type: String, long_form: '--suffix', short_form: '-x',
|
16
18
|
description: "`path/title.<md, markdown, txt>`"
|
17
19
|
|
18
|
-
action do |plate, *custom, title: nil, path: nil, timestamp: nil, suffix: nil|
|
20
|
+
action do |plate, *custom, title: nil, slug: nil, path: nil, timestamp: nil, suffix: nil|
|
19
21
|
custom = Hash[custom.map {|v| v.split('=')}]
|
20
22
|
JekyllPageBoilerplate.page plate, custom.merge({
|
21
|
-
title: title, path: path,
|
23
|
+
title: title, path: path, slug: slug,
|
22
24
|
suffix: suffix, timestamp: timestamp
|
23
25
|
})
|
24
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-page-boilerplate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Ferney
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bales
|
@@ -45,13 +45,13 @@ dependencies:
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 2.8.5
|
47
47
|
description: |+
|
48
|
-
A boilerplate is a markdown file you place under the `_boilerplates
|
48
|
+
A boilerplate is a markdown file you place under the `_boilerplates/` folder to generate new pages for jekyll.
|
49
49
|
|
50
50
|
|
51
51
|
It can automatically timestamp and title new pages.
|
52
52
|
|
53
53
|
|
54
|
-
It will also replacing any `{{ boilerplate.xxx }}` tags with content. Available tags include `.time, .title, .date, .
|
54
|
+
It will also replacing any `{{ boilerplate.xxx }}` tags with content. Available tags include `.time, .title, .date, .random`.
|
55
55
|
|
56
56
|
|
57
57
|
You can also provide custom tags with `boilerplate post nav_order=1` > `{{ boilerplate.nav_order }}`.
|
@@ -76,7 +76,9 @@ files:
|
|
76
76
|
- lib/jekyll_page_boilerplate/list.rb
|
77
77
|
- lib/jekyll_page_boilerplate/msg.rb
|
78
78
|
- lib/jekyll_page_boilerplate/msg/description.md
|
79
|
+
- lib/jekyll_page_boilerplate/msg/gem_description.md
|
79
80
|
- lib/jekyll_page_boilerplate/page.rb
|
81
|
+
- lib/jekyll_page_boilerplate/tags.rb
|
80
82
|
- lib/jekyll_page_boilerplate/version.rb
|
81
83
|
- lib/jekyll_page_boilerplate_cli.rb
|
82
84
|
homepage: https://github.com/CodeKarmaDev/jekyll-page-boilerplate
|