From 37e865a3db0ad6a211037d2330643d80be814f08 Mon Sep 17 00:00:00 2001 From: Suraj Nath Date: Mon, 22 May 2023 01:09:43 +0530 Subject: [PATCH] Add Rakefile, update readme, and config --- README.md | 25 ++++++++++++++++++------ Rakefile | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ _config.yml | 3 ++- 3 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 Rakefile diff --git a/README.md b/README.md index 2f99109..783a8d1 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,28 @@ Curated list of failures in software systems, and other literature around the sa See [failuremodes.dev](https://failuremodes.dev) for more details -### Questions, or concerns? -Send DM to [@electron0zero](https://twitter.com/electron0zero) +### Usage & Local Development -#### running locally -This site is built using jekyll, so you need to install it to run it locally +This site is built using jekyll, so you need to install it to run it locally, +jekyll is based on Ruby so you need Ruby and Bundler installed on your system. 0. [install jekyll](https://jekyllrb.com/docs/installation/) 1. git clone 2. install gems `bundle install` -3. start local server `jekyll server --trace` -3. start local server with drafts `jekyll server --trace --drafts` +3. start local server with `rake` or `rake preview` or `jekyll server --trace` if don't have rake installed. +4. start local server with drafts `jekyll server --trace --drafts` +5. Build website `rake build` or `jekyll build --trace` if don't have rake installed. +6. Create a new post with `rake post "Title of post"`, it will create a new file in `_posts` directory with current date and title of post. + +### Questions, or concerns? +Send DM to [@electron0zero](https://twitter.com/electron0zero) + + +### Contributing + +Contributions are welcome, to contribue: +1. follow Usage & Local Development section to setup local environment. +2. Create a new branch from `master` branch. +3. Create a new post (with `rake post`), and create a PR to `master` branch. +4. Once PR is merged, it will be deployed to [failuremodes.dev](https://failuremodes.dev) automatically. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..50f0ad0 --- /dev/null +++ b/Rakefile @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +# Rake tasks for Jekyll +require 'rake/clean' +require 'stringex' + +# <\!--more--\> is excerpt_separator +DEFAULT_TEXT = "Add first paragraph here \n\n\<\!--more--\>\n\nAdd more content here".freeze +POSTS_DIR = '_posts'.freeze +BUILD_DIR = '_site'.freeze + +CLEAN.include BUILD_DIR + +desc 'Build the site' +task :build do + sh 'jekyll', 'build', '--trace' +end + +desc 'Start web server to preview site' +task :preview do + sh 'jekyll', 'serve', '--watch', '--drafts', '--trace', '--port', ENV.fetch('PORT', '4000') +end + +# Hacking Rake for pretty args +# exit at the end of task so rake can not execute our args as task +# https://stackoverflow.com/a/36929059 + +desc 'Create a new post, usage: rake post "Title of post" "Link to the incident details page"' +task :post do + _, title, link = ARGV + title ||= 'Title of new Post' + link ||= 'Link to Incident details page' + timestamp = Time.now.strftime('%Y-%m-%d') + filepath = File.join(POSTS_DIR, "#{timestamp}-#{title.to_url}.md") + build_file(filepath, title, link, timestamp) + exit +end + +task default: :preview + +# create jekyll post file +def build_file(filepath, title, link, timestamp) + File.open(filepath, 'w') do |f| + f << "---\n" + f << "layout: post\n" + f << "title: \"#{title}\"\n" + f << "date: #{timestamp || Time.now.strftime('%Y-%m-%d')}\n" + f << "tags: ['New-Post', 'Tag']\n" + f << "---\n" + f << "\n" + f << "[see more details](#{link})\n\n#{DEFAULT_TEXT}\n" + end + puts "Created: #{filepath}" +end + diff --git a/_config.yml b/_config.yml index 903c8f5..3d7ee3e 100644 --- a/_config.yml +++ b/_config.yml @@ -46,7 +46,8 @@ kramdown: # posts to /incidents/ url parmalink # FIXME: find a better -permalink: /:title +permalink: /:year-:month-:day/:title/ + # pagination config paginate: 5