N
N
neodekvat092015-08-08 03:23:33
Blogs
neodekvat09, 2015-08-08 03:23:33

Automate posts in jekyll?

Hello, I recently got a burning desire to make a blog on github using jekyll.
Everything is fine, but how to automate the writing of posts, not to write the date in the file name every time, or the first three lines? (Like in hexo.io, or octopress).
And is it possible to make the url display the post id and not the slug ? Since, in small posts (for example, some quote book, which I almost want to do, short names, they are slugs, they do not make sense and only clog the url).
I read the documentation, but nothing is said about it, apparently everyone likes to write everything by hand, or I don’t know how to google (which is most likely).
I know I'm asking a lot, but please help, if at all possible, with these two problems >.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TyzhSysAdmin, 2015-08-08
@POS_troi

Regarding links:
Link jekyllrb.com/docs/permalinks
Config file: jekyllrb.com/docs/configuration
regarding generating new article file: (rake task from octopress)

desc "Begin a new post in #{source_dir}/#{posts_dir}"
task :new_post, :title do |t, args|
  if args.title
    title = args.title
  else
    title = get_stdin("Enter a title for your post: ")
  end
  raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
  mkdir_p "#{source_dir}/#{posts_dir}"
  filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
  if File.exist?(filename)
    abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
  end
  puts "Creating new post: #{filename}"
  open(filename, 'w') do |post|
    post.puts "---"
    post.puts "layout: post"
    post.puts "title: \"#{title.gsub(/&/,'&')}\""
    post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}"
    post.puts "comments: true"
    post.puts "categories: "
    post.puts "---"
  end
end

Well, or a bash/cmd script that will do it for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question