update_tags 0.0.1
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 +7 -0
- data/bin/update_tags +51 -0
- data/lib/update_tags.rb +103 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 69ec4948120440a717e986fd4f234335e8dece80e0a81e7d780ae5a4d6baafc3
|
4
|
+
data.tar.gz: 02d4c89d961614bad98a3fab0734f604956999049b8ddcbef84dab1e474ef06a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ad03b9b42459a1dda150edae1e17bc6a251461c76c80d28b9f0e89927d259c61c804f5fafea9f656e23d31fc5749d4164e72c91c099583177c2df14757bf7fb
|
7
|
+
data.tar.gz: 91403efaea60abfadbdc1da19f6ad0e2f5036d7efcb6460c41247059f316542ca486d9bb1bd722c6880b737a8529a5bd912e2a3689f26db5564f0048d6bc2cf8
|
data/bin/update_tags
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require "update_tags"
|
4
|
+
require "thor"
|
5
|
+
require "filewatcher"
|
6
|
+
|
7
|
+
# update_tags now
|
8
|
+
# update_tags now --at tag --template _includes/tag_index_page.md
|
9
|
+
#
|
10
|
+
# update_tags continuously
|
11
|
+
# update_tags continuously --at tag --template _includes/tag_index_page.md
|
12
|
+
|
13
|
+
class UpdateTagsCli < Thor
|
14
|
+
DEFAULT_TAG_DIRECTORY = "tag"
|
15
|
+
DEFAULT_PATH_TO_TAG_INDEX_PAGE_TEMPLATE = "_includes/tag_index_page.md"
|
16
|
+
|
17
|
+
class_option :at,
|
18
|
+
default: DEFAULT_TAG_DIRECTORY,
|
19
|
+
desc: "the directory in which to put the tag index pages"
|
20
|
+
|
21
|
+
class_option :template,
|
22
|
+
default: DEFAULT_PATH_TO_TAG_INDEX_PAGE_TEMPLATE,
|
23
|
+
desc: "the path to the file defining the tag index page template"
|
24
|
+
|
25
|
+
desc "now", "update your jekyll blog's tag index pages"
|
26
|
+
|
27
|
+
def now
|
28
|
+
UpdateTags.update(
|
29
|
+
tag_directory: options[:at],
|
30
|
+
path_to_tag_index_page_template: options[:template],
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "continuously", "update your jekyll blog's tag index pages continuously"
|
35
|
+
|
36
|
+
def continuously
|
37
|
+
UpdateTags.update(
|
38
|
+
tag_directory: options[:at],
|
39
|
+
path_to_tag_index_page_template: options[:template],
|
40
|
+
)
|
41
|
+
|
42
|
+
Filewatcher.new(["_posts", options[:template]]).watch do |changes|
|
43
|
+
UpdateTags.update(
|
44
|
+
tag_directory: options[:at],
|
45
|
+
path_to_tag_index_page_template: options[:template],
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
UpdateTagsCli.start(ARGV)
|
data/lib/update_tags.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require "front_matter_parser"
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
class UpdateTags
|
5
|
+
def self.update(tag_directory:, path_to_tag_index_page_template:)
|
6
|
+
new(tag_directory, path_to_tag_index_page_template).update
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :tag_directory, :path_to_tag_index_page_template
|
10
|
+
|
11
|
+
def initialize(tag_directory, path_to_tag_index_page_template)
|
12
|
+
@tag_directory = tag_directory
|
13
|
+
@path_to_tag_index_page_template = path_to_tag_index_page_template
|
14
|
+
end
|
15
|
+
|
16
|
+
def update
|
17
|
+
print "Updating tags..."
|
18
|
+
delete_tag_pages
|
19
|
+
create_tag_pages
|
20
|
+
print " Done.\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def delete_tag_pages
|
26
|
+
FileUtils.rm_rf(tag_directory)
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_tag_pages
|
30
|
+
FileUtils.mkdir(tag_directory)
|
31
|
+
|
32
|
+
tags.each do |tag|
|
33
|
+
File.write(
|
34
|
+
tag_index_page_path(tag),
|
35
|
+
tag_index_page_source(tag),
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def blog_post_filenames
|
41
|
+
@blog_post_filenames ||= Dir.entries("./_posts") - [".", ".."]
|
42
|
+
end
|
43
|
+
|
44
|
+
def tags
|
45
|
+
@tags ||= blog_post_filenames.inject([]) do |tags, blog_post_filename|
|
46
|
+
tags += FrontMatterParser::Parser
|
47
|
+
.parse_file(blog_post_file(blog_post_filename))
|
48
|
+
.front_matter["tags"]
|
49
|
+
end.uniq
|
50
|
+
end
|
51
|
+
|
52
|
+
def blog_post_file(blog_post_filename)
|
53
|
+
"./_posts/#{blog_post_filename}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def tag_index_page_path(tag)
|
57
|
+
"#{tag_directory}/#{url_friendly_tag(tag)}.md"
|
58
|
+
end
|
59
|
+
|
60
|
+
def url_friendly_tag(tag)
|
61
|
+
tag.downcase.split(" ").join("-")
|
62
|
+
end
|
63
|
+
|
64
|
+
def tag_index_page_front_matter_parser
|
65
|
+
@tag_index_page_front_matter_parser ||= FrontMatterParser::Parser
|
66
|
+
.parse_file(path_to_tag_index_page_template)
|
67
|
+
end
|
68
|
+
|
69
|
+
def tag_index_page_front_matter
|
70
|
+
@tag_index_page_front_matter ||= \
|
71
|
+
tag_index_page_front_matter_parser.front_matter.map do |key, value|
|
72
|
+
"#{key}: #{value}"
|
73
|
+
end.join("\n")
|
74
|
+
end
|
75
|
+
|
76
|
+
def tag_index_page_content
|
77
|
+
@tag_index_page_content ||= tag_index_page_front_matter_parser.content
|
78
|
+
end
|
79
|
+
|
80
|
+
def injected_liquid_for_tag_index_page(tag)
|
81
|
+
<<~INJECTED_LIQUID
|
82
|
+
{% assign tag = "#{tag}" %}
|
83
|
+
{% assign tagged_posts = "" | split: "" %}
|
84
|
+
{% for post in site.posts %}
|
85
|
+
{% if post.tags contains tag %}
|
86
|
+
{% assign tagged_posts = tagged_posts | push: post %}
|
87
|
+
{% endif %}
|
88
|
+
{% endfor %}
|
89
|
+
INJECTED_LIQUID
|
90
|
+
end
|
91
|
+
|
92
|
+
def tag_index_page_source(tag)
|
93
|
+
<<~TAG_INDEX_PAGE
|
94
|
+
---
|
95
|
+
#{tag_index_page_front_matter}
|
96
|
+
---
|
97
|
+
|
98
|
+
#{injected_liquid_for_tag_index_page(tag)}
|
99
|
+
|
100
|
+
#{tag_index_page_content}
|
101
|
+
TAG_INDEX_PAGE
|
102
|
+
end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: update_tags
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Pachulski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fileutils
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: filewatcher
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: front_matter_parser
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.0.1
|
69
|
+
description: Automatically update your jekyll blog's tag index pages for GitHub Pages
|
70
|
+
email: nick@pachulski.me
|
71
|
+
executables:
|
72
|
+
- update_tags
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- bin/update_tags
|
77
|
+
- lib/update_tags.rb
|
78
|
+
homepage: https://github.com/pachun/update_tags
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubygems_version: 3.3.7
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Jekyll blog post tags for GitHub Pages
|
101
|
+
test_files: []
|