From 4e776003a59e9a7a7e36b451a5c4281c2190bf69 Mon Sep 17 00:00:00 2001 From: Panos Sakkos Date: Wed, 7 Oct 2015 23:34:03 +0200 Subject: [PATCH] Added tag generation script --- _posts/2015-06-19-writing-posts.markup | 16 +++++++++++----- scripts/generate-tags | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100755 scripts/generate-tags diff --git a/_posts/2015-06-19-writing-posts.markup b/_posts/2015-06-19-writing-posts.markup index 6e9b6dd18..063fac31a 100644 --- a/_posts/2015-06-19-writing-posts.markup +++ b/_posts/2015-06-19-writing-posts.markup @@ -22,9 +22,15 @@ tags: [ 'tutorial' ] The *layout* and *section-type* are used by the theme. - 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 issue #2 - +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: + +
+./scripts/generate-tags
+
+ +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. diff --git a/scripts/generate-tags b/scripts/generate-tags new file mode 100755 index 000000000..63257ab13 --- /dev/null +++ b/scripts/generate-tags @@ -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