Commit 8ccec33d authored by Denis Salem's avatar Denis Salem
Browse files

still working on sub folders, fixing linking

parent 0bdbb65e
......@@ -151,3 +151,4 @@
TODO | Split unit-test and themes from main branch
TODO | Add Yaml comments in blog configuration
TODO | Catch invalid encoding at startup
TODO | Get formatted link to specified page/entry
<div class="entry .:GetEntryMetadataIfExists::CSS:." id="entry.:GetEntryID:." data-venc-tags=".:ForEntryTags::{0[tag]}:: :.">
<div class="permalink">
<h1><a href=".:GetRelativeOrigin:..:GetEntryURL:.">.:GetEntryTitle:.</a></h1>
<h1><a href=".:GetEntryURL:.">.:GetEntryTitle:.</a></h1>
<p>.:GetEntryDate:.</p>
</div>
.:GetEntryContent:.
......
......@@ -18,7 +18,7 @@
<body>
<header>
<h1>
<a href=".:IfInThread:: .:GetRelativeOrigin:. :: index.html :. ">
<a href=".:IfInThread:: .:GetRelativeOrigin:.index.html :: index.html :.">
<img id="banner" src=".:GetRelativeOrigin:..:GetBlogMetadataIfExists::banner:." alt=".:GetBlogName:." title=".:GetBlogName:." />
</a>
</h1>
......
......@@ -175,16 +175,7 @@ class DataStore:
return self.entries[self.requested_entry_index].date.strftime(self.blog_configuration["path"]["dates_directory_name"])
def get_entry_url(self, argv=list()):
sub_folders = self.blog_configuration["path"]["entries_sub_folders"].format(**{
"entry_id" : self.entries[self.requested_entry_index].id,
"entry_title" : self.entries[self.requested_entry_index].title
})
sub_folders = sub_folders+'/' if sub_folders != '' else ''
filename = self.blog_configuration["path"]["entry_file_name"].format(**{
"entry_id" : self.entries[self.requested_entry_index].id,
"entry_title" : self.entries[self.requested_entry_index].title
})
return urllib.parse.quote(sub_folders+filename, encoding=self.blog_configuration["path_encoding"])
return self.entries[self.requested_entry_index].url
def get_author_name(self, argv=list()):
return self.blog_configuration["author_name"]
......
......@@ -20,8 +20,10 @@
import datetime
import os
import time
import urllib.parse
import yaml
from venc2.helpers import die
from venc2.helpers import notify
......@@ -54,7 +56,7 @@ class EntryWrapper:
die(messages.missing_entry_content_inclusion)
class Entry:
def __init__(self, filename, sub_folders, previous_entry = None, encoding="utf-8"):
def __init__(self, filename, paths, previous_entry = None, encoding="utf-8"):
self.previous_entry = previous_entry
self.next_entry = None
......@@ -115,6 +117,18 @@ class Entry:
except KeyError:
die(messages.missing_mandatory_field_in_entry.format("tags", self.id))
params = {
"entry_id": self.id,
"entry_title": self.title
}
sf = paths["entries_sub_folders"].format(**params)
sf = sf+'/' if sf != '' else ''
self.url = ".:GetRelativeOrigin:."+urllib.parse.quote(
sf+paths["entry_file_name"].format(**params),
encoding=encoding
)
print(self.url)
self.categories_leaves = list()
self.raw_categories = [ c.strip() for c in metadata["categories"].split(',')]
try:
......@@ -134,7 +148,7 @@ class Entry:
pass
self.categories_tree = []
build_categories_tree(-1, self.raw_categories, self.categories_tree, None, -1, encoding=encoding, sub_folders=sub_folders["categories_sub_folders"])
build_categories_tree(-1, self.raw_categories, self.categories_tree, None, -1, encoding=encoding, sub_folders=paths["categories_sub_folders"])
self.html_categories_tree = None
''' Iterate through entries folder '''
......
......@@ -123,7 +123,7 @@ class Thread:
string = argv[1]
separator = argv[2]
if self.pages_count == 1 or not self.in_thread:
if self.pages_count == 1:
return str()
output = str()
......@@ -143,33 +143,33 @@ class Thread:
def if_in_first_page(self, argv):
if self.current_page == 0:
return argv[0]
return argv[0].strip()
else:
return argv[1]
return argv[1].strip()
def if_in_last_page(self, argv):
if self.current_page == len(self.pages) -1:
return argv[0]
return argv[0].strip()
else:
return argv[1]
return argv[1].strip()
def if_in_entry_id(self, argv):
return argv[2]
return argv[2].strip()
def if_in_categories(self, argv):
return argv[1]
return argv[1].strip()
def if_in_archives(self, argv):
return argv[1]
return argv[1].strip()
def if_in_thread(self, argv):
if self.in_thread:
return argv[0]
return argv[0].strip()
else:
return argv[1]
return argv[1].strip()
def format_filename(self, value):
try:
......@@ -187,8 +187,8 @@ class Thread:
die(messages.variable_error_in_filename.format(str(e)))
# Overridden in child class (EntriesThread)
def setup_sub_folders(self):
pass
def setup_context(self, entry):
self.current_entry = entry
def write_file(self, output, file_id):
if self.in_thread:
......@@ -205,7 +205,7 @@ class Thread:
stream.write(output)
stream.close()
def process_header(self):
def pre_iteration(self):
self.processor.forbidden = self.forbidden
self.output = ''.join(self.processor.batch_process(self.theme.header, "header.html").sub_strings)
self.processor.forbidden = []
......@@ -213,17 +213,43 @@ class Thread:
self.columns_number = self.datastore.blog_configuration["columns"]
self.columns_counter = 0
self.columns = [ '' for i in range(0, self.columns_number) ]
def post_iteration(self):
self.columns_counter = 0
for column in self.columns:
self.output += '<div id="__VENC_COLUMN_'+str(self.columns_counter)+'__" class="__VENC_COLUMN__">'+column+'</div>'
self.processor.forbidden = self.forbidden
self.output += ''.join(self.processor.batch_process(self.theme.footer, "footer.html").sub_strings)
self.write_file(self.output, self.page_number)
self.page_number += 1
self.current_page = self.page_number
def do_iteration(self, entry):
self.columns[self.columns_counter] += ''.join(self.processor.batch_process(entry.html_wrapper.above, entry.filename).sub_strings)
if entry.html_wrapper.required_content_pattern == ".:GetEntryPreview:.":
self.columns[self.columns_counter] += ''.join(self.processor.batch_process(entry.preview, entry.filename,).sub_strings)
elif entry.html_wrapper.required_content_pattern == ".:PreviewIfInThreadElseContent:." and self.in_thread:
self.columns[self.columns_counter] += ''.join(self.processor.batch_process(entry.preview, entry.filename,).sub_strings)
else:
self.columns[self.columns_counter] += ''.join(self.processor.batch_process(entry.content, entry.filename,).sub_strings)
self.columns[self.columns_counter] += ''.join(self.processor.batch_process(entry.html_wrapper.below, entry.filename).sub_strings)
self.columns_counter +=1
if self.columns_counter >= self.columns_number:
self.columns_counter = 0
# Must be called in child class
def do(self):
page_number = 0
self.page_number = 0
if self.pages_count == 0:
output = ''.join(self.processor.batch_process(self.theme.header, "header.html").sub_strings)
output += ''.join(self.processor.batch_process(self.theme.footer, "footer.html").sub_strings)
self.export_path.format(**{
"entry_id": '',
"entry_title":''
})
stream = codecs.open(
self.export_path +'/'+ self.format_filename(0),
'w',
......@@ -234,34 +260,9 @@ class Thread:
else:
for page in self.pages:
self.process_header()
self.pre_iteration()
for entry in page:
self.current_entry = entry
self.setup_sub_folders() #setup relative origin as well
self.columns[self.columns_counter] += ''.join(self.processor.batch_process(entry.html_wrapper.above, entry.filename).sub_strings)
if entry.html_wrapper.required_content_pattern == ".:GetEntryPreview:.":
self.columns[self.columns_counter] += ''.join(self.processor.batch_process(entry.preview, entry.filename,).sub_strings)
elif entry.html_wrapper.required_content_pattern == ".:PreviewIfInThreadElseContent:." and self.in_thread:
self.columns[self.columns_counter] += ''.join(self.processor.batch_process(entry.preview, entry.filename,).sub_strings)
else:
self.columns[self.columns_counter] += ''.join(self.processor.batch_process(entry.content, entry.filename,).sub_strings)
self.columns[self.columns_counter] += ''.join(self.processor.batch_process(entry.html_wrapper.below, entry.filename).sub_strings)
self.columns_counter +=1
if self.columns_counter >= self.columns_number:
self.columns_counter = 0
self.columns_counter = 0
for column in self.columns:
self.output += '<div id="__VENC_COLUMN_'+str(self.columns_counter)+'__" class="__VENC_COLUMN__">'+column+'</div>'
self.processor.forbidden = self.forbidden
self.output += ''.join(self.processor.batch_process(self.theme.footer, "footer.html").sub_strings)
self.write_file(self.output, page_number)
self.setup_context(entry)
self.do_iteration(entry)
page_number += 1
self.current_page = page_number
self.post_iteration()
......@@ -33,7 +33,7 @@ class CategoriesThread(Thread):
self.in_thread = True
def if_in_categories(self, argv):
return argv[0]
return argv[0].strip()
def do(self, root=None):
if root == None:
......
......@@ -33,7 +33,7 @@ class DatesThread(Thread):
self.in_thread = True
def if_in_archives(self, argv):
return argv[0]
return argv[0].strip()
def do(self):
for thread in self.datastore.entries_per_dates:
......
......@@ -40,10 +40,10 @@ class EntriesThread(Thread):
self.in_thread = False
def if_in_first_page(self, argv):
return argv[1]
return argv[1].strip()
def if_in_last_page(self, argv):
return argv[1]
return argv[1].strip()
def format_filename(self, value=None): #value ignored
try:
......@@ -59,21 +59,27 @@ class EntriesThread(Thread):
def if_in_entry_id(self, argv):
try:
if argv[0] == str(self.current_entry.id):
return argv[1]
return argv[1].strip()
else:
return argv[2]
return argv[2].strip()
except AttributeError:
return argv[2]
return argv[2].strip()
def setup_sub_folders(self):
def for_pages(self, argv):
list_lenght = int(argv[0])
string = argv[1]
separator = argv[2]
return ""
def setup_context(self, entry):
super().setup_context(entry)
export_path = self.export_path.format(**{
'entry_id': self.current_entry.id,
'entry_title': self.current_entry.title
})
self.relative_origin = str(''.join([ "../" for p in export_path.split('/')[1:] if p != ''])).replace("//",'/')
print(export_path, self.relative_origin, export_path.split('/')[1:])
os.makedirs(export_path, exist_ok=True)
def write_file(self, output, file_id):
......@@ -89,8 +95,15 @@ class EntriesThread(Thread):
stream.write(output)
stream.close()
def do(self):
self.page_number = 0
if len(self.pages):
super().do()
for page in self.pages:
for entry in page:
self.setup_context(entry)
self.pre_iteration()
self.do_iteration(entry)
self.post_iteration()
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