Code Monkey home page Code Monkey logo

Comments (3)

bewuethr avatar bewuethr commented on May 23, 2024

jekyll-compose is pretty close to what you're asking, if I understand correctly.

from jekyll.

y377 avatar y377 commented on May 23, 2024

If it is just _posts, if you define the defaults default layout in _config.yml, the author, then the preamble option does not need to be defined, but according to your description, I guess you want to use automation, which can write a _plugins/ create_post.rb

require 'fileutils'

Jekyll::Hooks.register :site, :after_init do |site|
  # 定义_posts目录路径
  posts_dir = File.join(site.source, '_posts')

  # 获取当前日期并创建文件名
  today = Date.today.strftime('%Y-%m-%d')
  filename = "#{today}-new-post.md"

  # 拼接文件路径
  filepath = File.join(posts_dir, filename)

  # 检查文件是否已存在
  if File.exist?(filepath)
    puts "文件 #{filename} 已存在,无需创建。"
  else
    # 创建文件并写入初始内容
    File.open(filepath, 'w') do |file|
      file.puts '---'
      file.puts 'layout: post'
      file.puts "title: Your Title Here"
      file.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"
      file.puts 'categories: [category1, category2]'
      file.puts 'tags: [tag1, tag2]'
      file.puts '---'
      file.puts ''
      file.puts 'Write your content here.'
    end
    puts "文件 #{filename} 创建成功!"
  end
end

This is just an example, modify as needed

from jekyll.

jekyllbot avatar jekyllbot commented on May 23, 2024

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the latest 3.x-stable or master/main branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider building it first as a plugin. Jekyll 3 introduced hooks which provide convenient access points throughout the Jekyll build pipeline whereby most needs can be fulfilled. If this is something that cannot be built as a plugin, then please provide more information about why in order to keep this issue open.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.

from jekyll.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.