diff --git a/lib/jekyll-asciidoc/integrator.rb b/lib/jekyll-asciidoc/integrator.rb index 2fa2521..cfe917e 100644 --- a/lib/jekyll-asciidoc/integrator.rb +++ b/lib/jekyll-asciidoc/integrator.rb @@ -79,6 +79,13 @@ def integrate document, collection_name = nil data.update adoc_data end + { 'category' => 'categories', 'tag' => 'tags' }.each do |sole_key, coll_key| + if (sole_val = data.delete sole_key) && + !((coll_val = (data[coll_key] ||= [])).include? sole_val) + coll_val << sole_val + end + end + case data['layout'] when nil document.content = %(#{StandaloneOptionLine}#{document.content}) unless data.key? 'layout' diff --git a/spec/fixtures/with_posts/_posts/2016-02-02-post-with-singular-vars.adoc b/spec/fixtures/with_posts/_posts/2016-02-02-post-with-singular-vars.adoc new file mode 100644 index 0000000..7564426 --- /dev/null +++ b/spec/fixtures/with_posts/_posts/2016-02-02-post-with-singular-vars.adoc @@ -0,0 +1,7 @@ += Post With Categories +:page-category: node +:page-categories: [code, javascript] +:page-tag: tip +:page-tags: [syntax, beginner] + +Lorem ipsum. diff --git a/spec/jekyll-asciidoc_spec.rb b/spec/jekyll-asciidoc_spec.rb index ca01c70..9d58495 100644 --- a/spec/jekyll-asciidoc_spec.rb +++ b/spec/jekyll-asciidoc_spec.rb @@ -759,6 +759,17 @@ end end + it 'should merge singular variables with collection variables' do + post = find_post '2016-02-02-post-with-singular-vars.adoc' + expect(post).not_to be_nil + expect(post.data['categories']).to eql(['code', 'javascript', 'node']) + expect(post.data['tags']).to eql(['syntax', 'beginner', 'tip']) + if ::Jekyll::MIN_VERSION_3 + file = output_file 'code/javascript/node/2016/02/02/post-with-singular-vars.html' + expect(::File).to exist(file) + end + end + it 'should convert revdate to local Time object and use it as date of post' do # NOTE Time.parse without time zone assumes time zone of site date = ::Time.parse('2016-06-15 10:30:00')