Added tag generation script
This commit is contained in:
parent
9024728953
commit
4e776003a5
2 changed files with 35 additions and 5 deletions
|
|
@ -22,9 +22,15 @@ tags: [ 'tutorial' ]
|
|||
|
||||
The *layout* and *section-type* are used by the theme.
|
||||
|
||||
<small>
|
||||
Note: *{ Personal }* generates a static page, just like all Jekyll themes.
|
||||
So we have to create the tag pages before building and publishing the site.
|
||||
For now, this has to be done manually, which practically means that you have to add a file under the tags directory, to represent the tag, similar to the existing tutorial.html file. I plan to write a script that will parse the posts, detect the tags and then auto-generate the tag pages.
|
||||
Tracked by <a href="https://github.com/PanosSakkos/personal-jekyll-theme/issues/2" target="_blank">issue #2</a>
|
||||
</small>
|
||||
As a result we have to create the tag pages before building and publishing the site.
|
||||
|
||||
In order to generate the tag pages, simply run the *generate-tags* script from the repo's root directory:
|
||||
|
||||
<pre style="text-align: left">
|
||||
./scripts/generate-tags
|
||||
</pre>
|
||||
|
||||
The script will parse all your posts, and generate the tag pages for the newly added tags.
|
||||
|
||||
If you are not using Github Pages, you can automate the execution of this script during build time.
|
||||
|
|
|
|||
24
scripts/generate-tags
Executable file
24
scripts/generate-tags
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require 'yaml'
|
||||
|
||||
POSTS_DIR = '_posts/'
|
||||
TAGS_DIR = 'tags/'
|
||||
|
||||
Dir.foreach(POSTS_DIR) do |post|
|
||||
|
||||
next if post == '.' or post == '..' or post == '.DS_Store'
|
||||
postYaml = YAML.load_file(POSTS_DIR + post)
|
||||
postYaml['tags'].each{|tag|
|
||||
|
||||
unless File.exist?(TAGS_DIR + tag + '.html')
|
||||
|
||||
puts('[+] Generating #' + tag + ' page')
|
||||
|
||||
File.open(TAGS_DIR + tag + '.html', 'w') {|f| f.write(
|
||||
"---\nlayout: tag\nsection-type: tag\ntitle: " + tag + "\n---\n## Tag")}
|
||||
|
||||
end
|
||||
}
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue