[RUBY] Directory is not created even if directory task is described in Rakefile

Event

The directory is not created even if the directory task is described in Rakefile.

Conclusion

In addition to describing (declaring) a directory task, that task I had to call it from somewhere to be executed.

Details

directory "doc"

desc "create task"
task "create" do
  cd "doc"
end
> rake -t create
** Invoke default (first_time)
** Invoke create (first_time)
** Execute create
cd doc
rake aborted!
Errno::ENOENT: No such file or directory @ dir_s_chdir - doc

I had to specify a directory task (named doc) as a prerequisite task for the create task.

directory "doc"

desc "create task"
task "create" => "doc" do
  cd "doc"
end
> rake -t create
** Invoke create (first_time)
** Invoke doc (first_time)
** Execute doc
mkdir -p doc
** Execute create
cd doc

I was worried about 4 hours. However, I can't find much information about Rake.

With asciidoctor involved, a little snake foot information ↓

Serpentine: Story Background

It's nice to be able to convert adoc files to html using asciidoctor Well, where I thought about publishing, I will upload it to Github Pages, Better yet, try using Hugo.

I was looking into it, but it seems that the directory where the images are placed Difficult to handle.

Put the content in contents/posts/api.adoc and the image directory is I wanted something like contents/posts/images/image01.png, For adoc, specify : imagesdir: ./images.

In the reference, : image: image01.png [].

$ asciidoctor -b html5 ./api.adoc

This should create contents/posts/api.html.

When I try to check HTML with hugo service -D, When hugo is involved, from publish/posts/api.html It is configured to reference publish/posts/api/images/image01.png.

Where did the api directory come from ...?

Place the image directory in contents/posts/api/images/image01.png If you replace it, there is no problem because it can be made consistent on the HTML display, but Then, it is different from the path when HTML is output by executing the command of asciidoctor (when previewing with marked2, it is troublesome because asciidoctor is used as the processor and preprocessor to output HTML).

So, hugo gave up and made HTML as it is with the behavior of the asciidoctor command Place the image file according to the generated image path ,.

When I tried using rake to do something like that, I got stuck in a strange place.

Serpent 2: Use asciidoctor with marked2

~/bin/asciidoctor-marked2


#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# frozen_string_literal: true

marked_origin = ENV["MARKED_ORIGIN"] || Dir.pwd
rbenv = File.expand_path("~/.rbenv/bin/rbenv")

asciidoctor = "#{rbenv} exec asciidoctor"

cmd = "#{asciidoctor} -a skip-front-matter --safe-mode safe --base-dir #{marked_origin} --backend html5 -o - -"
system(cmd)

Write a Ruby script like this and give it execute permission.

marked2.jpg

If you specify it with Custom Processor like this, you can preview asciidoc with marked2.

Serpent 3: Skip Front Matter required by Hugo when using asciidoctor command

With Hugo, I had to add Front Matter to the article, I was in trouble because it interfered with the processing of the asciidoctor command.

You can add -a skip-front-matter to asciidoctor.

https://docs.asciidoctor.org/asciidoctor/latest/html-backend/skip-front-matter/

Recommended Posts

Directory is not created even if directory task is described in Rakefile
Even if I write the setting of STRICT_QUOTE_ESCAPING in CATALINA_OPTS in tomcat8.5, it is not reflected.
[Rails] What to do if data is not registered in DB
Isn't it reflected even if the content is updated in Rails?
Data is not registered in Rails.
An active hash that can be treated as data even if it is not in the database
What to do if the prefix c is not bound in JSP
Memo: [Java] If a file is in the monitored directory, process it.
Phenomenon that cannot log out even though it is described in devise
Continuation ・ Active hash that can be handled as data even if it is not in the database ~ Display
Image is not displayed in production environment
Add if not in Set, error message if
Setting method that the size does not change even if CSS is changed
[Rails] If CSS is not applied in collection_select, check if class can be specified.
The problem that the JDK set in JAVA_HOME does not appear even if java -version is performed at the command prompt