Skip to content

Commit

Permalink
resolves #177 prepend baseurl to value of imagesdir if imagesdir valu…
Browse files Browse the repository at this point in the history
…e is root-relative (PR #276)
  • Loading branch information
mojavelinux authored Nov 6, 2023
1 parent 36706e3 commit d83d3f8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/master[
== Unreleased

* clear `:base_dir` option if value is `:docdir` and paths with docdir information is not available (such as to `asciidocify` filter) (#270)
* prepend baseurl to value of imagesdir if imagesdir value is root-relative (#177)
* convert documentation from README.adoc to an Antora component in the Asciidoctor docs site. (#238)
* bump requirements: Asciidoctor 2.0, Ruby 2.7, JRuby 9.4 (#237)
* explain Liquid include interactions in docs (#223)
Expand Down
7 changes: 4 additions & 3 deletions lib/jekyll-asciidoc/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def initialize config
'site-root' => ::Dir.pwd,
'site-source' => source,
'site-destination' => dest,
'site-baseurl' => config['baseurl'],
'site-baseurl' => (baseurl = config['baseurl']),
'site-url' => config['url'],
}
enable_attribute_value_coercion = asciidoctor_config[:enable_attribute_value_coercion]
Expand All @@ -115,8 +115,9 @@ def initialize config
attrs[key + '@'] = val
m_attr[key] = val
end
if (imagesdir = attrs['imagesdir']) && !(attrs.key? 'imagesoutdir') && (imagesdir.start_with? '/')
attrs['imagesoutdir'] = ::File.join dest, (imagesdir.chomp '@')
if (imagesdir = attrs['imagesdir']) && (imagesdir.start_with? '/')
attrs['imagesoutdir'] = ::File.join dest, (imagesdir.chomp '@') unless attrs.key? 'imagesoutdir'
attrs['imagesdir'] = baseurl + imagesdir unless baseurl.to_s.empty?
end
attrs[%(#{asciidoc_config['page_attribute_prefix']}published)] = '' if config['unpublished']
asciidoctor_config.extend Configured
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plugins:
- jekyll-asciidoc
baseurl: /projectname
asciidoctor:
attributes:
imagesdir: /images@
24 changes: 14 additions & 10 deletions spec/jekyll-asciidoc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,22 @@
end

describe 'imagesdir relative to root' do
use_fixture :imagesdir_relative_to_root
[nil, :with_baseurl].each do |config_path|
describe config_path do
use_fixture :imagesdir_relative_to_root, config_path

before do
site.object_id
end
before do
site.object_id
end

it 'should set imagesoutdir if imagesdir is relative to root' do
(expect (asciidoctor_config = site.config['asciidoctor'])).to be_a Hash
(expect (attrs = asciidoctor_config[:attributes])).to be_a Hash
(expect attrs['imagesdir']).to eql '/images@'
imagesoutdir_expected = File.join site.dest, (attrs['imagesdir'].chomp '@')
(expect attrs['imagesoutdir']).to eql imagesoutdir_expected
it 'should set imagesoutdir if imagesdir is relative to root' do
(expect (asciidoctor_config = site.config['asciidoctor'])).to be_a Hash
(expect (attrs = asciidoctor_config[:attributes])).to be_a Hash
(expect attrs['imagesdir']).to eql (config_path == :with_baseurl ? '/projectname' : '') + '/images@'
imagesoutdir_expected = File.join site.dest, '/images'
(expect attrs['imagesoutdir']).to eql imagesoutdir_expected
end
end
end
end

Expand Down

0 comments on commit d83d3f8

Please sign in to comment.