From 4d164ca3f42ee46caf71bc5e3a36a17460d5bca8 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 8 Dec 2023 09:40:51 -0800 Subject: [PATCH] Add jekyll-import command. We have been asking folks to run 'jekyll import' for a while, but it requires a Gemfile. Not everyone wants to have a Gemfile or knows how to set one up. I'd like to be a bit more independent of Jekyll and its not-always-entirely-working system for external subcommands. This commit adds a new top-level 'jekyll-import' command so that this gem can handle importing without requiring a Gemfile with :jekyll_plugins. --- README.markdown | 2 +- docs/_docs/contributing.md | 4 ++-- docs/_layouts/importer.html | 2 +- exe/jekyll-import | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100755 exe/jekyll-import diff --git a/README.markdown b/README.markdown index 5db39417..14d7f389 100644 --- a/README.markdown +++ b/README.markdown @@ -12,7 +12,7 @@ The new __Jekyll__ command for importing from various blogs to Jekyll format. ### Jekyll v2.x and higher 1. Install the _rubygem_ with `gem install jekyll-import`. -2. Run `jekyll import IMPORTER [options]` +2. Run `jekyll-import IMPORTER [options]` ### Jekyll v1.x diff --git a/docs/_docs/contributing.md b/docs/_docs/contributing.md index 822083c3..af138326 100644 --- a/docs/_docs/contributing.md +++ b/docs/_docs/contributing.md @@ -15,7 +15,7 @@ Found an issue with one of the importers? Sorry about that! In order to better a 1. Collection information about your system: operating system and version, Ruby version, Jekyll version, jekyll-import version. 2. Which importer are you using? Note this. 3. Collect the relevant data. This may be data from your database or input file. This will help us diagnose where the issue occurred. -4. Ensure the `--trace` option is specified if you're running `jekyll import` from the command-line. +4. Ensure the `--trace` option is specified if you're running `jekyll-import` from the command-line. 4. [Open a new issue]({{ site.repository }}/issues/new) describing the four above points, as well as what you expected the outcome of your incantation to be. You should receive help soon. As always, check out [our help repo](https://talk.jekyllrb.com/) if you just have a question. @@ -90,5 +90,5 @@ Once you have your importer working (test with `script/console`), then you're re `./docs/_importers/columbus.md`. Take a look at one of the other importers as an example. You just add basic usage and you're golden. All set? Add everything to a branch on your fork of `jekyll-import` and -[submit a pull request](https://github.com/jekyll/jekyll-import/compare/). +[submit a pull request](https://github.com/jekyll/jekyll-import/compare/). Thank you! diff --git a/docs/_layouts/importer.html b/docs/_layouts/importer.html index 92f9a1b8..e0b34781 100644 --- a/docs/_layouts/importer.html +++ b/docs/_layouts/importer.html @@ -20,7 +20,7 @@

Invocation

Sample snippet to invoke the importer: -

jekyll import {{ page.cmd_name }}{% if page.cmd_opts %} {{ page.cmd_opts | map: 'switch' | join: ' ' }}{% endif %}
+
jekyll-import {{ page.cmd_name }}{% if page.cmd_opts %} {{ page.cmd_opts | map: 'switch' | join: ' ' }}{% endif %}

diff --git a/exe/jekyll-import b/exe/jekyll-import new file mode 100755 index 00000000..cea8394f --- /dev/null +++ b/exe/jekyll-import @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +STDOUT.sync = true + +$LOAD_PATH.unshift File.expand_path("../lib", __dir__) + +require 'jekyll-import' +require 'jekyll/commands/import' +require 'mercenary' + +Mercenary.program(:jekyll_import) do |p| + p.version JekyllImport::VERSION + p.description "Import from various blogs to Jekyll format." + p.syntax "jekyll-import [options]" + + # Create all the subcommands for the importers. + JekyllImport.add_importer_commands(p) + + p.action do |args, _| + if args.empty? + Jekyll.logger.error "A subcommand is required." + puts p + abort + else + subcommand = args.first + unless p.has_command? subcommand + Jekyll.logger.abort_with "fatal: 'jekyll-import #{args.first}'" \ + " could not be found." + end + end + end +end