如何将参数传递给Ruby脚本

时间:2018-08-27 14:09:38

标签: ruby wordpress export jekyll

我正在尝试将WordPress中的帖子导入jekyll

https://import.jekyllrb.com/docs/wordpressdotcom/

我应该跑:

$ ruby -rubygems -e 'require "jekyll-import";
JekyllImport::Importers::WordpressDotCom.run({
  "source" => "wordpress.xml",
  "no_fetch_images" => false,
  "assets_folder" => "assets"
})'

但是我需要先修改脚本 https://github.com/jekyll/jekyll-import/blob/v0.14.0/lib/jekyll-import/importers/wordpressdotcom.rb

如何运行下载的脚本wordpressdotcom.rb传递诸如sourceassets_folder之类的参数?

1 个答案:

答案 0 :(得分:0)

这似乎是旧的jekyll-import v1.x方法。新的导入方法是从命令行运行jekyll import

只需运行:

gem install jekyll-import

然后:

jekyll import wordpressdotcom --help

输出:

Usage:

  jekyll import wordpressdotcom [options]

Options:
            --source FILE  WordPress export XML file (default: "wordpress.xml")
            --no-fetch-images  Do not fetch the images referenced in the posts
            --assets_folder FOLDER  Folder where assets such as images will be do

如您所见,您可以在命令行上指定sourceassets_folder

如果您想修改源代码并自己运行gem

第一:

git clone https://github.com/jekyll/jekyll-import
bundle install

现在,请根据需要编辑代码,然后:

rake console

您将获得一个irb控制台,您可以在其中运行

JekyllImport::Importers::WordpressDotCom.run(...)

如果您想将修改后的gem安装到系统中,则:

rake install