Commit 89c342a9 authored by Denis Salem's avatar Denis Salem
Browse files

done with disabling thread / categories tree

parent bd5cde33
......@@ -125,19 +125,21 @@
DONE | Fix: Import asset from external theme if necessary.
DONE | Export empty blog.
WIP | Allow disabling exportation of specific kind of thread.
TODO | Remove illegal character from path.
TODO | Open with navigator manual.
TODO | Add relevant templates for themes.
TODO | Add support for embed content (peertube, youtube, soundcloud, etc)
TODO | Export entry in nicely named folder instead of permalink
TODO | Add categories tree in entry.
TODO | Client-side search engine.
TODO | Fix unit test.
TODO | Remove illegal character from path.
TODO | Serv page.
TODO | Open with navigator manual.
TODO | Reorganize themes dependencies in setup (adding default templates, scripts, and pages to include).
TODO | Add relevant templates for themes.
TODO | Split install and blog creation chapter in tutorial.
TODO | fix FAQ https://stackoverflow.com/questions/14547631/python-locale-error-unsupported-locale-setting.
TODO | fix FAQ latex2mathml is incomplete.
TODO | Change nomenclature: Most of the usual patterns are changed. Fix doc.
TODO | Add translation for Deutsch and Spanish.
TODO | Client-side search engine.
TODO | Fix unit test.
# version 2.x.x
......
......@@ -24,7 +24,7 @@
</h1>
<h2>CATEGORIES</h2>
<div id="categories">
.:RecursiveFor::BlogCategories::<ul>::<li><a href="{relativeOrigin}{categoryPath}" title="{count} publications">{item}</a>::</li>::</ul>:.
.:TreeForBlogCategories::<ul>::<li><a href="{path}" title="{count} publications">{item}</a>::</li>::</ul>:.
</div>
<h2 id="archivesHeader">ARCHIVES</h2>
<ul id="archives">.:ForBlogDates::<li><a href="{dateUrl}" title="{count} publications">{date}</a></li>:: :.</ul>
......
......@@ -79,7 +79,8 @@ non_contextual_pattern_names_datastore = {
"ForEntryAuthors" : "for_entry_authors",
"ForEntryTags" : "for_entry_tags",
"ForBlogDates" : "for_blog_dates",
"ForBlogCategories" : "for_blog_categories"
"LeafForBlogCategories" : "leaf_for_blog_categories",
"TreeForBlogCategories" : "tree_for_blog_categories"
}
non_contextual_pattern_names_ml = {
......
......@@ -20,6 +20,7 @@
from venc2.datastore.configuration import get_blog_configuration
from venc2.datastore.entry import yield_entries_content
from venc2.datastore.entry import Entry
from venc2.datastore.metadata import build_categories_tree
from venc2.datastore.metadata import MetadataNode
def merge(iterable, argv):
......@@ -29,30 +30,6 @@ def merge(iterable, argv):
]
)
def perform_recursion(open_string, content, separator, close_string, nodes):
output_string = open_string
for node in sorted(nodes, key = lambda x : x.value):
variables = {
"value" : node.value,
"count" : node.count,
"weight" : node.weight,
"path" : node.path
}
if len(node.childs) == 0:
output_string += content.format(variables) + separator
else:
output_string += content.format(variables) + perform_recursion(
open_string,
content,
separator,
close_string,
node.childs
)
return output_string + close_string
class DataStore:
def __init__(self):
self.blog_configuration = get_blog_configuration()
......@@ -61,7 +38,9 @@ class DataStore:
self.entries_per_dates = list()
self.entries_per_categories = list()
self.requested_entry_index = 0
self.max_category_weight = 1
self.html_categories_tree = None
''' Entry index is different from entry id '''
entry_index = 0
for filename in yield_entries_content():
......@@ -83,29 +62,7 @@ class DataStore:
''' Update entriesPerCategories '''
for category in self.entries[-1].raw_categories:
branch = category.split(' > ')
path = ".:GetRelativeOrigin:."
root = self.entries_per_categories
for node_name in branch:
if node_name == '':
continue
path += node_name+'/'
if not node_name in [metadata.value for metadata in root]:
root.append(MetadataNode(node_name, entry_index))
root[-1].path = path
root = root[-1].childs
else:
for node in root:
if node.value == node_name:
node.count +=1
node.related_to.append(entry_index)
root = node.childs
build_categories_tree(entry_index, self.entries[-1].raw_categories, self.entries_per_categories, self.max_category_weight, self.set_max_category_weight)
entry_index += 1
''' Setup BlogDates Data '''
......@@ -118,6 +75,10 @@ class DataStore:
"weight": node.weight
})
def set_max_category_weight(self, value):
self.max_category_weight = value
return value
def get_blog_metadata(self, argv):
# if exception is raised it will be automatically be catch by processor.
return self.blog_configuration[argv[0]]
......@@ -235,22 +196,58 @@ class DataStore:
dates = [o for o in self.blog_dates if o["date"] not in self.disable_threads]
return merge(dates, argv)
def perform_recursion(self, opening_node, opening_branch, closing_branch, closing_node, tree):
output_string = opening_node
for node in sorted(tree, key = lambda x : x.value):
if node.value in self.disable_threads:
continue
variables = {
"item" : node.value,
"count" : node.count,
"weight" : round(node.weight / self.max_category_weight,2),
"path" : node.path
}
if len(node.childs) == 0:
output_string += opening_branch.format(**variables) + closing_branch.format(**variables)
else:
output_string += opening_branch.format(**variables) + self.perform_recursion(
opening_node,
opening_branch,
closing_branch,
closing_node,
node.childs
) + closing_branch.format(**variables)
if output_string == opening_node+closing_node:
return ""
return output_string + closing_node
def tree_for_blog_categories(self, argv):
# compute once categories tree and deliver baked html
if self.html_categories_tree == None:
self.html_categories_tree = self.perform_recursion(
argv[0], #opening_node
argv[1], #opening_branch
argv[2], #closing_branch
argv[3], #closing_node
self.entries_per_categories
)
return self.html_categories_tree
def for_entry_tags(self, argv):
return merge(self.entries[self.requested_entry_index].tags, argv)
def for_entry_authors(self, argv):
return merge(self.entries[self.requested_entry_index].authors, argv)
def for_blog_categories(self, argv):
def leaf_for_blog_categories(self, argv):
output_string = str()
output_string += perform_recursion(
argv[0],
argv[1],
argv[2],
argv[3],
self.entries_per_categories
)
return output_string
......
......@@ -26,6 +26,7 @@ from venc2.helpers import die
from venc2.helpers import notify
from venc2.l10n import messages
from venc2.datastore.metadata import build_categories_tree
from venc2.datastore.metadata import MetadataNode
from venc2.patterns.processor import PreProcessor
......@@ -115,7 +116,6 @@ class Entry:
die(messages.missing_mandatory_field_in_entry.format("tags", self.id))
self.categories_leaves = list()
self.categories_nodes_reference = list()
self.raw_categories = [ c.strip() for c in metadata["categories"].split(',')]
try:
for category in self.raw_categories:
......@@ -133,8 +133,8 @@ class Entry:
except IndexError : # when list is empty
pass
def SetupCategoriesNodesReference(self, categoriesTree):
pass
self.categories_tree = []
build_categories_tree(-1, self.raw_categories, self.categories_tree, -1)
''' Iterate through entries folder '''
def yield_entries_content():
......@@ -179,19 +179,6 @@ def get_latest_entryID():
return 0
'''
def GetCategoriesList(entries):
output = list()
for entry in entries.keys():
stream = entries[entry].split("---\n")[0]
data = yaml.load(stream)
if data != None:
for category in data["categories"].split(","):
if (not category in output) and category != '':
output.append(category)
return output
def GetEntriesPerCategories(entries):
entriesPerCategories = list()
for entry in entries.keys():
......
......@@ -28,49 +28,28 @@ class MetadataNode:
self.related_to = [entry_index]
self.childs = list()
def get_metadata_by_name(keys, name):
for key in keys:
if key.value == name:
return key
return None
''' Need refactorisation '''
def get_dates_list(keys):
output = list()
max_weight = 0
for key in keys:
if max_weight < key.count:
max_weight = key.count
output.append({"date": key.value, "count":key.count,"dateUrl":key.value})
for key in output:
key["weight"] = str(int((key["count"]/max_weight)*10))
return sorted(output, key = lambda date: datetime.datetime.strptime(date["date"], dates_directory_name))
def get_metadata_tree_max_weight(metadata, maxWeight=0):
current_max_weight = max_weight
for current in metadata:
if current.count > current_max_weight:
current_max_weight = current.count
m = get_metadata_tree_max_weight(current.childs, max_weight=current_max_weight)
if m > current_max_weight:
current_max_weight = m
return current_max_weight
def get_metadata_tree(metadata, root=list(), max_weight=None):
nodes = root
for current in metadata:
nodes.append()
nodes[current.value] = dict()
nodes[current.value]["__categoryPath"] = current.path
if max_weight != None:
node[current.value]["__count"] = current.count
node[current.value]["__weight"] = int((current.count/max_weight) * 10)
if len(current.childs) != 0:
node[current.value]["_nodes"] = dict()
get_metadatas_tree(current.childs, node[metadata.value]["_nodes"], max_weight)
return node
def build_categories_tree(entry_index, input_list, output_tree, max_weight, set_max_weight=None):
for category in input_list:
branch = category.split(' > ')
path = ".:GetRelativeOrigin:."
root = output_tree
for node_name in branch:
if node_name == '':
continue
path += node_name+'/'
if not node_name in [metadata.value for metadata in root]:
root.append(MetadataNode(node_name, entry_index))
root[-1].path = path
root = root[-1].childs
else:
for node in root:
if node.value == node_name:
node.count +=1
if set_max_weight != None and node.count > max_weight:
max_weight = set_max_weight(node.count)
node.related_to.append(entry_index)
root = node.childs
......@@ -77,14 +77,6 @@ def merge_dictionnaries(current, public):
d.update(public)
return d
''' deprecated
def GetFormattedDate(unformattedDate, dateFormat):
data = unformattedDate.split('-')
return data.strftime(
dateFormat
)
'''
def get_list_of_pages(entries_per_page, entries_count):
list_of_pages = list()
pages_count = math.ceil(entries_count/entries_per_page)
......
......@@ -182,8 +182,6 @@ class Processor():
",;"+pattern+";;"+";;".join(argv)+";,",
error_origin = [':'+str(e)[1:-1]+':','{0['+str(e)[1:-1]+']}']
)
if pattern != "RecursiveFor":
raise e
except AttributeError as e:
output = self.handle_error(
......
......@@ -27,7 +27,7 @@ class CategoriesThread(Thread):
super().__init__(prompt, datastore, theme, patterns)
self.filename = self.datastore.blog_configuration["path"]["index_file_name"]
self.relative_origin = "../"
self.relative_origin = ""
self.in_thread = True
self.export_path = "blog/"
......@@ -46,6 +46,7 @@ class CategoriesThread(Thread):
export_path = self.export_path
self.export_path += node.value+'/'
self.relative_origin = ''.join([ '../' for a in self.export_path.split("/")[1:-1] ])
# Get entries
try:
......
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