Skip to content

Commit

Permalink
Added tag generation script
Browse files Browse the repository at this point in the history
  • Loading branch information
le4ker committed Oct 7, 2015
1 parent 9024728 commit 4e77600
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
16 changes: 11 additions & 5 deletions _posts/2015-06-19-writing-posts.markup
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 24 additions & 0 deletions scripts/generate-tags
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4e77600

Please sign in to comment.