From 9fe7b0151fda669b7eb40d598b0b6d6159fa35c0 Mon Sep 17 00:00:00 2001 From: username Date: Mon, 3 Jun 2019 18:10:47 +0200 Subject: [PATCH] posts should now merge with normal pages --- lib/jekyll/helper/rdf_generator_helper.rb | 23 +++++++++++-------- test/cases/PostMerge/Gemfile | 5 ++++ test/cases/PostMerge/_config.yml | 11 +++++++++ test/cases/PostMerge/_data/knowledge-base.ttl | 8 +++++++ test/cases/PostMerge/_data/prefixes.sparql | 3 +++ test/cases/PostMerge/_layouts/default.html | 16 +++++++++++++ .../PostMerge/_posts/2019-02-12-Blogpost.md | 1 + test/cases/PostMerge/blog.html | 5 ++++ test/cases/PostMerge/test_post_merge.rb | 20 ++++++++++++++++ .../test_prefixes.rb | 2 +- 10 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 test/cases/PostMerge/Gemfile create mode 100644 test/cases/PostMerge/_config.yml create mode 100644 test/cases/PostMerge/_data/knowledge-base.ttl create mode 100644 test/cases/PostMerge/_data/prefixes.sparql create mode 100644 test/cases/PostMerge/_layouts/default.html create mode 100644 test/cases/PostMerge/_posts/2019-02-12-Blogpost.md create mode 100644 test/cases/PostMerge/blog.html create mode 100644 test/cases/PostMerge/test_post_merge.rb diff --git a/lib/jekyll/helper/rdf_generator_helper.rb b/lib/jekyll/helper/rdf_generator_helper.rb index 28e57214..b04989f5 100644 --- a/lib/jekyll/helper/rdf_generator_helper.rb +++ b/lib/jekyll/helper/rdf_generator_helper.rb @@ -132,21 +132,26 @@ def extract_list_resources path result end + def assimilate_pages(page, pages) + pages.map!{|old_page| + if (old_page.url.chomp('.html') == page.url.chomp('.html')) + changes||=true + page.assimilate_page(old_page) + page + else + old_page + end + } + end + def create_page(site, resource, mapper) Jekyll::JekyllRdf::Helper::RdfPageHelper.prepare_resource resource, mapper page = Jekyll::Page.new(site, site.source, resource.filedir, resource.filename) page.re_init_as_rdf(resource, mapper) if(page.complete) changes = false - site.pages.map!{|old_page| - if (old_page.url.chomp('.html') == page.url.chomp('.html')) - changes||=true - page.assimilate_page(old_page) - page - else - old_page - end - } + assimilate_pages(page, site.pages) + assimilate_pages(page, site.posts.docs) unless changes site.pages << page end diff --git a/test/cases/PostMerge/Gemfile b/test/cases/PostMerge/Gemfile new file mode 100644 index 00000000..74fb4acd --- /dev/null +++ b/test/cases/PostMerge/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem "theme-gem", :path => '../../theme-gem' + gem 'jekyll-rdf', :path => '../../../' +end diff --git a/test/cases/PostMerge/_config.yml b/test/cases/PostMerge/_config.yml new file mode 100644 index 00000000..d9b6fd22 --- /dev/null +++ b/test/cases/PostMerge/_config.yml @@ -0,0 +1,11 @@ +baseurl: "" +url: "http://example.org/" + +theme: theme-gem +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p ?o}" + default_template: "default" + diff --git a/test/cases/PostMerge/_data/knowledge-base.ttl b/test/cases/PostMerge/_data/knowledge-base.ttl new file mode 100644 index 00000000..39002fe1 --- /dev/null +++ b/test/cases/PostMerge/_data/knowledge-base.ttl @@ -0,0 +1,8 @@ +@prefix rdfs: . +@prefix owl: . + + a owl:Ontology ; + rdfs:label "My Jekyll RDF Blog" . + + a owl:Ontology ; + rdfs:label "My Jekyll RDF Blogpost" . diff --git a/test/cases/PostMerge/_data/prefixes.sparql b/test/cases/PostMerge/_data/prefixes.sparql new file mode 100644 index 00000000..a37afee6 --- /dev/null +++ b/test/cases/PostMerge/_data/prefixes.sparql @@ -0,0 +1,3 @@ +PREFIX ex: +PREFIX jb: +PREFIX rdfs: diff --git a/test/cases/PostMerge/_layouts/default.html b/test/cases/PostMerge/_layouts/default.html new file mode 100644 index 00000000..e0ef6b5b --- /dev/null +++ b/test/cases/PostMerge/_layouts/default.html @@ -0,0 +1,16 @@ +--- +rdf_prefix_path: "_data/prefixes.sparql" +--- + + + Rdf Post Merge Test + + + + +

My Jekyll RDF Blog


+ {{content}}
+ {{ page.rdf }}
+ + + diff --git a/test/cases/PostMerge/_posts/2019-02-12-Blogpost.md b/test/cases/PostMerge/_posts/2019-02-12-Blogpost.md new file mode 100644 index 00000000..110457f0 --- /dev/null +++ b/test/cases/PostMerge/_posts/2019-02-12-Blogpost.md @@ -0,0 +1 @@ +This is a Blogpost diff --git a/test/cases/PostMerge/blog.html b/test/cases/PostMerge/blog.html new file mode 100644 index 00000000..ac960f63 --- /dev/null +++ b/test/cases/PostMerge/blog.html @@ -0,0 +1,5 @@ +--- +layout: ontology +--- + +A page diff --git a/test/cases/PostMerge/test_post_merge.rb b/test/cases/PostMerge/test_post_merge.rb new file mode 100644 index 00000000..fcaa704f --- /dev/null +++ b/test/cases/PostMerge/test_post_merge.rb @@ -0,0 +1,20 @@ +require 'test_helper' + +class TestPrefixes < Test::Unit::TestCase + context "Page merging feature" do + include RdfTestUtility + should "also merge posts" do + setup_jekyll File.dirname(__FILE__) + + content = [] + file = File.read(File.join(@source, "_site/2019/02/12/Blogpost.html")) + content = file[/\(.|\s)*\<\/body\>/][6..-6].strip.split("
").map do |entry| + entry.strip + end + + assert_equal "

My Jekyll RDF Blog

", content[0] + assert_equal "This is a Blogpost", content[1] + assert_equal "http://example.org/2019/02/12/Blogpost", content[2] + end + end +end diff --git a/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb b/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb index c2daa658..7b1ad46b 100644 --- a/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb +++ b/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb @@ -13,7 +13,7 @@ class TestPrefixes < Test::Unit::TestCase end assert_equal "

My Jekyll RDF Blog

", content[0] - assert_equal "

This is a Blogpost

", content[1] + assert_equal "This is a Blogpost", content[1] # this line has to be uncommented once page.rdf is set in posts #assert_equal "My Jekyll RDF Blogpost", content[2] assert_equal "My Jekyll RDF Blog", content[3]