AKSW / jekyll-rdf

📃 A Jekyll plugin to include RDF data in your static site or build a complete site for your RDF graph
http://aksw.org/Projects/JekyllRDF
Other
57 stars 10 forks source link

Content and interited layouts cause multiplication of content #77

Closed white-gecko closed 6 years ago

white-gecko commented 7 years ago

I've put the MWE in https://github.com/white-gecko/MWE-jekyll-rdf-layouts-content-issue

even simpler: There are two layouts _layouts/default.html and _layouts/document.html

default:

{{ content }}

document:

PageRDF (this URI): {{ page.rdf }}, rdfs:label: {{ page.rdf | rdf_property: '<http://www.w3.org/2000/01/rdf-schema#label>' }}</br>
Content:
{{ content }}

a file hallo/index.md:

---
layout: "default"
---

This is index in Hallo

a graph:

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ex: <http://example.org/> .

ex: a foaf:Document ;
    rdfs:label "This is the base page" .

<http://example.org/hallo/> a foaf:Document .

ex:project a foaf:Document ;
    rdfs:label "Projects" .

_config.yml

# Site settings
url: http://example.org/
baseurl: ""

# Build settings
markdown: kramdown

# jekyll-rdf
plugins:
    - jekyll-rdf
jekyll_rdf:
    path: "rdf-data/content.ttl"
    class_template_mappings:
        "http://xmlns.com/foaf/0.1/Document" : "document.html"

Depending on the order of the pages in the classmap the pages are replicating the content of the previous page additionally the content of hallo/index.md is also rendered to all pages:

classMapped: http://xmlns.com/foaf/0.1/Document : http://example.org/ : document.html 
classMapped: http://xmlns.com/foaf/0.1/Document : http://example.org/hallo/ : document.html 
classMapped: http://xmlns.com/foaf/0.1/Document : http://example.org/project : document.html 

http://example.org/project/:

    PageRDF (this URI): http://example.org/project
    rdfs:label: Projects

Content:

    PageRDF (this URI): http://example.org/hallo/
    rdfs:label:

Content:

    PageRDF (this URI): http://example.org/
    rdfs:label: This is the base page

Content:

This is index in Hallo

Expected is:

    PageRDF (this URI): http://example.org/
    rdfs:label: This is the base page

Content:
    PageRDF (this URI): http://example.org/hallo/
    rdfs:label: 

Content:

This is index in Hallo

and

    PageRDF (this URI): http://example.org/project
    rdfs:label: Projects

Content:
Simaris commented 7 years ago

after a period of longer testing, I determined the problem not to be in jekyll-rdf but in Jekyll itself. For conformation, I wrote a simple plug-in with the following code (corresponds to https://jekyllrb.com/docs/plugins/#generators)

module Jekyll

  class CategoryPage < Page
    def initialize(site, base, layout, path)
      @site = site
      @base = base
      @name = path
      self.process(@name)
      self.read_yaml(File.join(base, '_layouts'), layout)
    end
  end

  class CategoryPageGenerator < Generator
    safe true

    def generate(site)
      site.pages << CategoryPage.new(site, site.source, "document.html", "Testfile1.html")
      site.pages << CategoryPage.new(site, site.source, "document.html", "Testfile2.html")
      site.pages << CategoryPage.new(site, site.source, "document.html", "Testfile3.html")
      site.pages << CategoryPage.new(site, site.source, "document.html", "Testfile4.html")
    end
  end

end

I also simplified our Layouts:

---
---
<!DOCTYPE html>
<html>
<body>
<h1>Default</h1>
{{ content }}
</body>
</html>
---
layout: "default"
---

<ul>
    <li>
        ListElement
    </li>
</ul>
<p>
    Content:<br/>
    {{ content }}
</p>

For Testfile4.html we still get an output like that

<head></head><body>
<h1>Default</h1>
<ul>
<!--    <li>PageRDF (this URI): </li>
    <li>rdfs:label: </li> -->
    <li>
        ListElement
    </li>
</ul>
<p>
    Content:<br>
    </p><ul>
<!--    <li>PageRDF (this URI): </li>
    <li>rdfs:label: </li> -->
    <li>
        ListElement
    </li>
</ul>
<p>
    Content:<br>
    </p><ul>
<!--    <li>PageRDF (this URI): </li>
    <li>rdfs:label: </li> -->
    <li>
        ListElement
    </li>
</ul>
<p>
    Content:<br>
    </p><ul>
<!--    <li>PageRDF (this URI): </li>
    <li>rdfs:label: </li> -->
    <li>
        ListElement
    </li>
</ul>
<p>
    Content:<br>
    </p><p>This is index in Hallo</p>

<p></p>

<p></p>

<p></p>

<p></p>
</body>

I also tried to reverse the order of site.pages with .reverse! which didn't fix the problem. That means, we are not able to fix the problem by resetting a variable between the rendering processes, since the rendering process itself is not pluggable yet(see https://github.com/jekyll/jekyll/issues/5645).

white-gecko commented 7 years ago

Ok, so maybe we should open an issue an jekyll together with our MWE. Maybe we can also provide a pull request for jekyll?

white-gecko commented 7 years ago

https://github.com/jekyll/jekyll/issues/6296

white-gecko commented 7 years ago

@Simaris could you please clarify our use case in the MWE?