Commit 171b7d9f authored by Denis Salem's avatar Denis Salem
Browse files

almost done with jsonld archives

parent 02a98632
......@@ -191,6 +191,7 @@
TODO | Automatically add entries categories to entries tags.
TODO | Make entry URL nicer when filename is index.html and has subfolder.
TODO | Catch "OSError: [Errno 98] Address already in use".
TODO | Improve sub folder management in Entry and EntriesThread.
# version 3.x.x
TODO | Add support for plugin.
......
......@@ -166,11 +166,6 @@ class DataStore:
"weight": node.weight
})
# Setup archives as jsonld if any
if self.enable_jsonld:
for archive in self.entries_per_dates:
self.archives_to_jsonld(archive.value, archive.related_to)
def root_site_to_jsonld(self):
self.root_as_jsonld = {
"@context": "http://schema.org",
......@@ -195,13 +190,15 @@ class DataStore:
**self.optionals_schemadotorg
}
def archives_to_jsonld(self, archive_value, related_to):
def archives_to_jsonld(self, archive_value):
blog_url = self.blog_configuration["blog_url"]
blog_name = self.blog_configuration["blog_name"]
self.archives_as_jsonld[archive_value] = {
"@context": "http://schema.org",
"@type": ["Blog","WebPage"],
"@id" : self.blog_configuration["blog_url"]+'/'+archive_value+"/archives.jsonld",
"name": self.blog_configuration["blog_name"],
"url": self.blog_configuration["blog_url"]+'/'+archive_value,
"@id" : blog_url+'/'+archive_value+"/archives.jsonld",
"name": blog_name,
"url": blog_url+'/'+archive_value,
"description": self.blog_configuration["blog_description"],
"author": {
"@type" : "Person",
......@@ -211,9 +208,17 @@ class DataStore:
},
"keywords" : self.blog_configuration["blog_keywords"],
"inLanguage" : self.blog_configuration["blog_language"],
"license" : {
"@type": "CreativeWork",
"name": self.blog_configuration["license"]
"license" : self.root_as_jsonld["license"],
"breadcrumb" : {
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"item": {
"@id": blog_url+"/root.jsonld",
"url": blog_url,
"name": blog_name
}
}]
},
"blogPost" : [],
**self.optionals_schemadotorg
......@@ -256,8 +261,24 @@ class DataStore:
"publisher" : publisher,
"url" : entry.url.replace(".:GetRelativeOrigin:.", self.blog_configuration["blog_url"]+"/"),
"breadcrumb" : {
"itemListElement": [
]
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"item": {
"@id": blog_url+"/root.jsonld",
"url": blog_url,
"name": blog_name
}
},
{
"@type": "ListItem",
"position": 2,
"item": {
"@id": blog_url+"/root.jsonld",
"url": blog_url,
"name": entry.title
}
}]
},
"relatedLink" : [ c["path"] for c in entry.categories_leaves],
**optionals
......@@ -265,7 +286,7 @@ class DataStore:
self.entries_as_jsonld[entry.id] = doc
# TODO 2.x.x : TRY AVOID DEREFERENCE HERE
blogPost = {
blog_post = {
"@type": doc["@type"],
"@id": doc["@id"],
"headline":entry.title,
......@@ -276,6 +297,12 @@ class DataStore:
"url": doc["url"]
}
self.root_as_jsonld["blogPost"].append(blog_post)
# Setup archives as jsonld if any
entry_formatted_date = entry.formatted_date
if entry_formatted_date not in self.archives_as_jsonld.keys():
self.archives_to_jsonld(entry_formatted_date)
self.archives_as_jsonld[entry.formatted_date]["blogPost"].append(blog_post)
def get_chapters(self, argv):
......
......@@ -140,12 +140,12 @@ class Entry:
"entry_title": self.title
}
sf = paths["entries_sub_folders"].format(**params).replace(' ','-')
sf = sf+'/' if sf != '' else ''
self.sub_folder = sf+'/' if sf != '' else ''
try:
self.url = ".:GetRelativeOrigin:."+urllib.parse.quote(sf+paths["entry_file_name"].format(**params), encoding=encoding)
self.url = ".:GetRelativeOrigin:."+urllib.parse.quote(self.sub_folder+paths["entry_file_name"].format(**params), encoding=encoding)
except UnicodeEncodeError as e:
self.url = ".:GetRelativeOrigin:."+sf+paths["entry_file_name"].format(**params)
self.url = ".:GetRelativeOrigin:."+self.sub_folder+paths["entry_file_name"].format(**params)
notify("\"{0}\": ".format(sf+paths["entry_file_name"].format(**params))+str(e), color="YELLOW")
self.categories_leaves = list()
......
......@@ -18,15 +18,20 @@
# along with VenC. If not, see <http://www.gnu.org/licenses/>.
import os
import json
from venc2.prompt import notify
from venc2.threads import Thread
class ArchivesThread(Thread):
def __init__(self, prompt, datastore, theme, patterns, forbidden):
super().__init__(prompt, datastore, theme, patterns, forbidden)
self.filename = self.datastore.blog_configuration["path"]["index_file_name"]
self.sub_folders = self.datastore.blog_configuration["path"]["dates_sub_folders"]
if len(self.sub_folders) and self.sub_folders[-1] != '/':
self.sub_folders += '/'
self.relative_origin = str("../"+''.join([ "../" for p in self.sub_folders.split('/') if p != ''])).replace("//",'/')
self.in_thread = True
......@@ -55,6 +60,20 @@ class ArchivesThread(Thread):
)
])
super().do()
if self.datastore.enable_jsonld:
blog_url = self.datastore.blog_configuration["blog_url"]
self.datastore.archives_as_jsonld[thread.value]["breadcrumb"]["itemListElement"].append({
"@type": "ListItem",
"position": 2,
"item": {
"@id": blog_url+'/'+self.sub_folders+thread.value+"/archives.jsonld",
"url": blog_url+'/'+self.sub_folders+thread.value,
"name": self.datastore.blog_configuration["blog_name"] +' | '+thread.value
}
})
dump = json.dumps(self.datastore.archives_as_jsonld[thread.value])
f = open("blog/"+self.sub_folders+'/'+thread.value+"/archives.jsonld", 'w')
f.write(dump)
def JSONLD(self, argv):
if self.current_page == 0:
......
#! /usr/bin/python3
from venc2.helpers import get_formatted_message
from venc2.prompt import get_formatted_message
def run_tests(tests_name, tests):
print(tests_name)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment