{"id":19842,"date":"2014-04-21T13:01:14","date_gmt":"2014-04-21T05:01:14","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=19842"},"modified":"2025-04-04T01:45:14","modified_gmt":"2025-04-03T17:45:14","slug":"jekyll-plugin","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/","title":{"rendered":"How to Manage Multiple Drafts in Jekyll"},"content":{"rendered":"<p>Although Jekyll is a static website generator, it allows for the use of plugins to extend its functionality. Continuing our discussion from the previous post, we previously <a href=\"https:\/\/www.hongkiat.com\/blog\/jekyll-draft\/\">created drafts<\/a> and placed them in a special folder named <strong>_drafts<\/strong>.<\/p>\n<p>When ready to publish, we move these drafts to the <code>_posts<\/code> folder and ensure they follow the proper naming format.<\/p>\n<p>This process is straightforward for managing one or two drafts, but handling 5-10 drafts can be cumbersome. Renaming files and specifying the correct dates manually can be tedious. Let\u2019s explore how we can simplify this workflow using a Jekyll plugin.<\/p>\n<h2>Getting Started<\/h2>\n<p>First, create a new folder named <strong>_plugins<\/strong>. Jekyll searches and executes plugins from within this folder. Next, create a file named <code>publisher.rb<\/code> in this folder. You can choose any name for this file.<\/p>\n<p>We will use a Jekyll plugin created by <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/jeffreysambells.com\/\">Jeffrey Sambells<\/a>. This plugin streamlines the process of publishing drafts by properly renaming files, setting the date, and updating the Front Matter section of the post.<\/p>\n<p>Copy the following code from this <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/gist.github.com\/iamamused\/4689219\"><strong>Gist page<\/strong><\/a> and paste it into the <code>publisher.rb<\/code> file:<\/p>\n<pre>\r\nmodule Jekyll\r\n  class PostPublisher &lt; Generator\r\n    safe false\r\n\r\n    def replace(filepath, regexp, *args, &block)\r\n      content = File.read(filepath).gsub(regexp, *args, &block)\r\n      File.open(filepath, 'wb') { |file| file.write(content) }\r\n    end\r\n\r\n    def generate(site)\r\n      @files = Dir[\"_publish\/*\"]\r\n      @files.each_with_index do |f, i|\r\n        now = DateTime.now.strftime(\"%Y-%m-%d %H:%M:%S\")\r\n        replace(f, \/^date: unpublished\/mi) { |match| \"date: \\\"\" + now + \"\\\"\" }\r\n        now = Date.today.strftime(\"%Y-%m-%d\")\r\n        File.rename(f, \"_posts\/#{now}-#{File.basename(f)}\")\r\n      end\r\n    end\r\n  end\r\nend\r\n<\/pre>\n<p>If your Jekyll server is running, restart it to apply the plugin.<\/p>\n<h2>Using the Plugin<\/h2>\n<p>To use the plugin, create a new folder named <strong>_publish<\/strong>. Move your post drafts to this folder when ready to publish. Set the <code>date<\/code> in the draft\u2019s Front Matter to <code>unpublished<\/code> as shown below:<\/p>\n<pre>\r\n---\r\nlayout: post\r\ntitle: \"This is My Second Post\"\r\ndate: unpublished\r\n---\r\n<\/pre>\n<p>Next, move the draft to the <strong>_publish<\/strong> folder.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/jekyll-plugin\/move-draft.jpg\" height=\"174\" width=\"500\" alt=\"Moving draft to _publish folder\"><\/figure>\n<p>Jekyll will automatically move the file to the <strong>_posts<\/strong> folder, set the post date, and publish the post.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/jekyll-plugin\/post-published.jpg\" height=\"174\" width=\"500\" alt=\"Published post in _posts folder\"><\/figure>\n<h2>Final Thoughts<\/h2>\n<p>We\u2019ve seen how Jekyll can be extended with plugins. In this post, we used a plugin to simplify the process of publishing drafts. For more Jekyll plugins, visit the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/jekyllrb.com\/docs\/plugins\/#available_plugins\">Available Plugins<\/a> page.<\/p>\n<p>In the next post, we\u2019ll demonstrate how to publish a Jekyll blog to an online server via FTP. Stay tuned!<\/p>","protected":false},"excerpt":{"rendered":"<p>Although Jekyll is a static website generator, it allows for the use of plugins to extend its functionality. Continuing our discussion from the previous post, we previously created drafts and placed them in a special folder named _drafts. When ready to publish, we move these drafts to the _posts folder and ensure they follow the&hellip;<\/p>\n","protected":false},"author":113,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[352],"tags":[3093],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Manage Multiple Drafts in Jekyll - Hongkiat<\/title>\n<meta name=\"description\" content=\"Although Jekyll is a static website generator, it allows for the use of plugins to extend its functionality. Continuing our discussion from the previous\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Manage Multiple Drafts in Jekyll\" \/>\n<meta property=\"og:description\" content=\"Although Jekyll is a static website generator, it allows for the use of plugins to extend its functionality. Continuing our discussion from the previous\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2014-04-21T05:01:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-03T17:45:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/jekyll-plugin\/move-draft.jpg\" \/>\n<meta name=\"author\" content=\"Thoriq Firdaus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@tfirdaus\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Thoriq Firdaus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/\"},\"author\":{\"name\":\"Thoriq Firdaus\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e7948c7a175d211496331e4b6ce55807\"},\"headline\":\"How to Manage Multiple Drafts in Jekyll\",\"datePublished\":\"2014-04-21T05:01:14+00:00\",\"dateModified\":\"2025-04-03T17:45:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/\"},\"wordCount\":313,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/jekyll-plugin\\\/move-draft.jpg\",\"keywords\":[\"Jekyll\"],\"articleSection\":[\"Web Design\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/\",\"name\":\"How to Manage Multiple Drafts in Jekyll - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/jekyll-plugin\\\/move-draft.jpg\",\"datePublished\":\"2014-04-21T05:01:14+00:00\",\"dateModified\":\"2025-04-03T17:45:14+00:00\",\"description\":\"Although Jekyll is a static website generator, it allows for the use of plugins to extend its functionality. Continuing our discussion from the previous\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/jekyll-plugin\\\/move-draft.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/jekyll-plugin\\\/move-draft.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/jekyll-plugin\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Manage Multiple Drafts in Jekyll\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e7948c7a175d211496331e4b6ce55807\",\"name\":\"Thoriq Firdaus\",\"description\":\"Thoriq is a writer for Hongkiat.com with a passion for web design and development. He is the author of Responsive Web Design by Examples, where he covered his best approaches in developing responsive websites quickly with a framework.\",\"sameAs\":[\"https:\\\/\\\/thoriq.com\",\"https:\\\/\\\/x.com\\\/tfirdaus\"],\"jobTitle\":\"Web Developer\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/thoriq\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Manage Multiple Drafts in Jekyll - Hongkiat","description":"Although Jekyll is a static website generator, it allows for the use of plugins to extend its functionality. Continuing our discussion from the previous","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/","og_locale":"en_US","og_type":"article","og_title":"How to Manage Multiple Drafts in Jekyll","og_description":"Although Jekyll is a static website generator, it allows for the use of plugins to extend its functionality. Continuing our discussion from the previous","og_url":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2014-04-21T05:01:14+00:00","article_modified_time":"2025-04-03T17:45:14+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/jekyll-plugin\/move-draft.jpg","type":"","width":"","height":""}],"author":"Thoriq Firdaus","twitter_card":"summary_large_image","twitter_creator":"@tfirdaus","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Thoriq Firdaus","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/"},"author":{"name":"Thoriq Firdaus","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e7948c7a175d211496331e4b6ce55807"},"headline":"How to Manage Multiple Drafts in Jekyll","datePublished":"2014-04-21T05:01:14+00:00","dateModified":"2025-04-03T17:45:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/"},"wordCount":313,"commentCount":1,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/jekyll-plugin\/move-draft.jpg","keywords":["Jekyll"],"articleSection":["Web Design"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/","url":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/","name":"How to Manage Multiple Drafts in Jekyll - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/jekyll-plugin\/move-draft.jpg","datePublished":"2014-04-21T05:01:14+00:00","dateModified":"2025-04-03T17:45:14+00:00","description":"Although Jekyll is a static website generator, it allows for the use of plugins to extend its functionality. Continuing our discussion from the previous","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/jekyll-plugin\/move-draft.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/jekyll-plugin\/move-draft.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/jekyll-plugin\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Manage Multiple Drafts in Jekyll"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e7948c7a175d211496331e4b6ce55807","name":"Thoriq Firdaus","description":"Thoriq is a writer for Hongkiat.com with a passion for web design and development. He is the author of Responsive Web Design by Examples, where he covered his best approaches in developing responsive websites quickly with a framework.","sameAs":["https:\/\/thoriq.com","https:\/\/x.com\/tfirdaus"],"jobTitle":"Web Developer","url":"https:\/\/www.hongkiat.com\/blog\/author\/thoriq\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-5a2","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/19842","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/113"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=19842"}],"version-history":[{"count":3,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/19842\/revisions"}],"predecessor-version":[{"id":73683,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/19842\/revisions\/73683"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=19842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=19842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=19842"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=19842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}