Skip to content

Commit

Permalink
posts should now merge with normal pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Simaris committed Jun 23, 2019
1 parent 46c890c commit 66da5e7
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 10 deletions.
23 changes: 14 additions & 9 deletions lib/jekyll/helper/rdf_generator_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/cases/PostMerge/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'
group :jekyll_plugins do
gem "theme-gem", :path => '../../theme-gem'
gem 'jekyll-rdf', :path => '../../../'
end
11 changes: 11 additions & 0 deletions test/cases/PostMerge/_config.yml
Original file line number Diff line number Diff line change
@@ -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"

8 changes: 8 additions & 0 deletions test/cases/PostMerge/_data/knowledge-base.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#>.

<http://example.org/blog> a owl:Ontology ;
rdfs:label "My Jekyll RDF Blog" .

<http://example.org/2019/02/12/Blogpost> a owl:Ontology ;
rdfs:label "My Jekyll RDF Blogpost" .
3 changes: 3 additions & 0 deletions test/cases/PostMerge/_data/prefixes.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PREFIX ex: <http://example.org/>
PREFIX jb: <http://jekyllrdf.biz/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
16 changes: 16 additions & 0 deletions test/cases/PostMerge/_layouts/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
rdf_prefix_path: "_data/prefixes.sparql"
---
<html>
<head>
<title>Rdf Post Merge Test</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>My Jekyll RDF Blog</h1><br/>
{{content}}<br/>
{{ page.rdf }}<br/>
</body>
</html>

1 change: 1 addition & 0 deletions test/cases/PostMerge/_posts/2019-02-12-Blogpost.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a Blogpost
5 changes: 5 additions & 0 deletions test/cases/PostMerge/blog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: ontology
---

A page
21 changes: 21 additions & 0 deletions test/cases/PostMerge/test_post_merge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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"))
assert !file[/\<body\>(.|\s)*\<\/body\>/].nil?, "The file _site/2019/02/12/Blogpost.html should contain <body> ... </body> if merged correctly."
content = file[/\<body\>(.|\s)*\<\/body\>/][6..-6].strip.split("<br/>").map do |entry|
entry.strip
end

assert_equal "<h1>My Jekyll RDF Blog</h1>", content[0]
assert_equal "http://example.org/2019/02/12/Blogpost", content[2]
assert_equal "This is a Blogpost", content[1]
end
end
end
2 changes: 1 addition & 1 deletion test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TestPrefixes < Test::Unit::TestCase
end

assert_equal "<h1>My Jekyll RDF Blog</h1>", content[0]
assert_equal "<p>This is a Blogpost</p>", 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]
Expand Down

0 comments on commit 66da5e7

Please sign in to comment.