Commit a0fc8c19 authored by Denis Salem's avatar Denis Salem
Browse files

fix get previous/next entry pattern

parent e7f193a8
authorDescription: I'm a artist and software engineer
authorEmail: denissalem 47 tuxfamily D07 org
authorName: Denis Salem
blogDescription: A fancy static blog generator for everyone!
blogKeywords: blog static free software generator web content python script linux
blogLanguage: en
blogName: VenC
blogUrl: https://denissalem.tuxfamily.org/VenC
columns: 1
dateFormat: '%A %d. %B %Y'
entriesPerPages: 5
ftpHost: Nom d'hôte FTP
license: CC By-SA
codeHighlightCssOverride: true
markup_language: 'Markdown'
path:
categoryDirectoryName: '{category}'
datesDirectoryName: '%m-%Y'
entryFileName: entry{0[entryId]}.html
ftp: Chemin absolu de votre blog sur l'hôte FTP.
indexFileName: index{0[pageNumber]}.html
rssFileName: feed.xml
reverseThreadOrder: false
rssThreadLenght: 5
textEditor: gvim
banner: 'https://download.tuxfamily.org/dsalem/img/2017_-_Denis_Salem_-_CC_By_SA_-_VenC-logo.svg'
</div>
<footer id="__VENC_NAVIGATION__">
.:GetPreviousPage:: <a id="previous" href="{0[destinationPageUrl]} "></a>:.
<ul id="pagesList">.:PagesList::5::<li><a href="{0[pageUrl]}">{0[pageNumber]}</a></li>:: . :.</ul>
.:GetNextPage:: <a id="next" href="{0[destinationPageUrl]} "></a>:.
.:GetPreviousPage:: <a id="previous" href="{destination_page_url} "></a>:.
<ul id="pagesList">.:ForPages::5::<li><a href="{page_url}">{page_number}</a></li>:: . :.</ul>
.:GetNextPage:: <a id="next" href="{destination_page_url} "></a>:.
</footer>
</body>
</html>
......@@ -120,19 +120,19 @@
DONE | add entry preview / full content.
DONE | Support for video.
DONE | Support for audio.
TODO | Add relevant templates for themes.
TODO | Add categories tree in entry.
TODO | Reorganize themes dependencies in setup (adding default templates, scripts, and pages to include).
TODO | SSH SUPPORT.
TODO | Split install and blog creation chapter in tutorial.
TODO | Fix: Import asset from external theme if necessary.
TODO | Allow disabling exportation of specific kind of thread.
TODO | Add more specific pattern to detect location (IfInCategories,IfInArchives,IfInFirstPage).
TODO | Remove illegal character from path.
TODO | Export empty blog.
TODO | Open with navigator manual.
TODO | Add relevant templates for themes.
TODO | Add categories tree in entry.
TODO | Serv page.
TODO | Reorganize themes dependencies in setup (adding default templates, scripts, and pages to include).
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 | Remove illegal character from path.
TODO | Open with navigator manual.
TODO | Change nomenclature: Most of the usual patterns are changed. Fix doc.
TODO | Add translation for Deutsch and Spanish.
TODO | Client-side search engine.
......
<audio controls style="width: 100%">
{source}
Your browser does not support the audio element.
</audio>
<footer>
.:GetPreviousPage::<a href="{0[destinationPageUrl]}">Précédent</a>:.
<ul>.:PagesList::5::<li><a href="{0[pageUrl]}">{0[pageNumber]}</a></li>:: :.</ul>
.:GetNextPage::<a href="{0[destinationPageUrl]}">Suivant</a>:.
.:GetPreviousPage::<a href="{destination_page_url}">Précédent</a>:.
<ul>.:ForPages::5::<li><a href="{page_url}">{page_number}</a></li>:: :.</ul>
.:GetNextPage::<a href="{destination_page_url}">Suivant</a>:.
</footer>
</body>
</html>
<video controls poster="{poster}" style="width: 100%;">
{source}
Your browser does not support the video tag.
</video>
</div>
<footer id="__VENC_NAVIGATION__">
.:GetPreviousPage:: <a id="previous" href="{0[destinationPageUrl]} "></a>:.
<ul id="pagesList">.:PagesList::5::<li><a href="{0[pageUrl]}">{0[pageNumber]}</a></li>:: . :.</ul>
.:GetNextPage:: <a id="next" href="{0[destinationPageUrl]} "></a>:.
.:GetPreviousPage:: <a id="previous" href="{destination_page_url} "></a>:.
<ul id="pagesList">.:ForPages::5::<li><a href="{page_url}">{page_number}</a></li>:: . :.</ul>
.:GetNextPage:: <a id="next" href="{destination_page_url} "></a>:.
</footer>
</body>
</html>
<audio controls style="width: 100%">
{source}
Your browser does not support the audio element.
</audio>
</div>
<footer id="__VENC_NAVIGATION__">
.:GetPreviousPage:: <a id="previous" href="{0[destinationPageUrl]} "></a>:.
<ul id="pagesList">.:PagesList::5::<li><a href="{0[pageUrl]}">{0[pageNumber]}</a></li>:: . :.</ul>
.:GetNextPage:: <a id="next" href="{0[destinationPageUrl]} "></a>:.
.:GetPreviousPage:: <a id="previous" href="{destination_page_url} "></a>:.
<ul id="pagesList">.:ForPages::5::<li><a href="{page_url}">{page_number}</a></li>:: . :.</ul>
.:GetNextPage:: <a id="next" href="{destination_page_url} "></a>:.
</footer>
</body>
</html>
<video controls poster="{poster}" style="width: 100%;">
{source}
Your browser does not support the video tag.
</video>
......@@ -46,7 +46,7 @@ from venc2.threads.main import MainThread
# Initialisation of environment
datastore = DataStore()
code_highlight = CodeHighlight(datastore.blog_configuration["codeHighlightCssOverride"])
code_highlight = CodeHighlight(datastore.blog_configuration["code_highlight_css_override"])
non_contextual_pattern_names_datastore = {
# General entry data
......@@ -143,6 +143,7 @@ def export_blog(argv=list()):
for entry in datastore.get_entries():
try:
markup_language = getattr(entry, "markup_language")
except AttributeError:
markup_language = datastore.blog_configuration["markup_language"]
......@@ -204,12 +205,12 @@ def edit_and_export(argv):
die(messages.missing_params.format("--edit-and-export"))
try:
proc = subprocess.Popen([datastore.blog_configuration["textEditor"], argv[0]])
proc = subprocess.Popen([datastore.blog_configuration["text_editor"], argv[0]])
while proc.poll() == None:
pass
except TypeError:
die(messages.unknown_text_editor.format(datastore.blog_configuration["textEditor"]))
die(messages.unknown_text_editor.format(datastore.blog_configuration["text_editor"]))
except:
raise
......
......@@ -93,12 +93,12 @@ def new_entry(argv):
stream.close()
try:
command = blog_configuration["textEditor"].split(' ')
command = blog_configuration["text_editor"].split(' ')
command.append(output_filename)
subprocess.call(command)
except FileNotFoundError:
die(messages.unknown_command.format(blog_configuration["textEditor"]))
die(messages.unknown_command.format(blog_configuration["text_editor"]))
notify(messages.entry_written)
......@@ -106,30 +106,30 @@ def new_blog(argv):
if len(argv) < 1:
die(Messages.missingParams.format("--new-blog"))
default_configuration = {"blogName": messages.blog_name,
"textEditor": "nano",
"dateFormat": "%A %d. %B %Y",
"authorName": messages.your_name,
"blogDescription": messages.blog_description,
"blogKeywords": messages.blog_keywords,
"authorDescription": messages.about_you,
default_configuration = {"blog_name": messages.blog_name,
"text_editor": "nano",
"date_format": "%A %d. %B %Y",
"author_name": messages.your_name,
"blog_description": messages.blog_description,
"blog_keywords": messages.blog_keywords,
"author_description": messages.about_you,
"license": messages.license,
"blogUrl": messages.blog_url,
"ftpHost": messages.ftp_host,
"blogLanguage": messages.blog_language,
"authorEmail": messages.your_email,
"codeHighlightCssOverride": False,
"blog_url": messages.blog_url,
"ftp_host": messages.ftp_host,
"blog_language": messages.blog_language,
"author_email": messages.your_email,
"code_highlight_css_override": False,
"path": {"ftp": messages.ftp_path,
"indexFileName": "index{0[pageNumber]}.html",
"categoryDirectoryName": "{category}",
"datesDirectoryName": "%Y-%m",
"entryFileName": "entry{0[entryId]}.html",
"rssFileName": "feed.xml"},
"entriesPerPages": 10,
"index_file_name": "index{page_number}.html",
"category_directory_name": "{category}",
"dates_directory_name": "%Y-%m",
"entry_file_name": "entry{entry_id}.html",
"rss_file_name": "feed.xml"},
"entries_per_pages": 10,
"columns": 1,
"rssThreadLenght": 5,
"reverseThreadOrder": True,
"markup_language": "markdown"}
"rss_thread_lenght": 5,
"reverse_thread_order": True,
"markup_language": "Markdown"}
for folder_name in argv:
try:
os.mkdir(folder_name)
......@@ -143,7 +143,7 @@ def new_blog(argv):
os.mkdir(folder_name+'/'+"includes")
os.mkdir(folder_name+'/'+"extra")
os.mkdir(folder_name+'/'+"templates")
stream = codecs.open(folder_name+'/'+'blogConfiguration.yaml', 'w',encoding="utf-8")
stream = codecs.open(folder_name+'/'+'blog_configuration.yaml', 'w',encoding="utf-8")
yaml.dump(default_configuration, stream, default_flow_style=False, allow_unicode=True)
notify(messages.blog_created)
......@@ -26,25 +26,25 @@ from venc2.l10n import messages
def get_blog_configuration():
try:
blog_configuration = yaml.load(open(os.getcwd()+"/blogConfiguration.yaml",'r').read())
blog_configuration = yaml.load(open(os.getcwd()+"/blog_configuration.yaml",'r').read())
mandatory_fields = [
"blogName",
"textEditor",
"dateFormat",
"authorName",
"blogDescription",
"blogKeywords",
"authorDescription",
"blog_name",
"text_editor",
"date_format",
"author_name",
"blog_description",
"blog_keywords",
"author_description",
"license",
"blogUrl",
"ftpHost",
"blogLanguage",
"authorEmail",
"entriesPerPages",
"blog_url",
"ftp_host",
"blog_language",
"author_email",
"entries_per_pages",
"columns",
"rssThreadLenght",
"reverseThreadOrder",
"rss_thread_lenght",
"reverse_thread_order",
"markup_language"
]
......@@ -55,11 +55,11 @@ def get_blog_configuration():
notify(messages.missing_mandatory_field_in_blog_conf.format(field),"RED")
mandatory_fields = [
"indexFileName",
"categoryDirectoryName",
"datesDirectoryName",
"entryFileName",
"rssFileName",
"index_file_name",
"category_directory_name",
"dates_directory_name",
"entry_file_name",
"rss_file_name",
"ftp"
]
......@@ -70,7 +70,7 @@ def get_blog_configuration():
if not blog_configuration["markup_language"] in ["none", "Markdown", "reStructuredText"]:
everything_is_okay = False
notify(messages.unknown_markup_language.format(blog_configuration["markup_language"], "blogConfiguration.yaml"),"RED")
notify(messages.unknown_markup_language.format(blog_configuration["markup_language"], "blog_configuration.yaml"),"RED")
if not everything_is_okay:
exit()
......
......@@ -67,8 +67,8 @@ class DataStore:
self.entries.append(Entry(filename))
''' Update entriesPerDates '''
if self.blog_configuration["path"]["datesDirectoryName"] != '':
formatted_date = self.entries[-1].date.strftime(self.blog_configuration["path"]["datesDirectoryName"])
if self.blog_configuration["path"]["dates_directory_name"] != '':
formatted_date = self.entries[-1].date.strftime(self.blog_configuration["path"]["dates_directory_name"])
entries_index = self.get_entries_index_for_given_date(formatted_date)
if entries_index != None:
self.entries_per_dates[entries_index].count +=1
......@@ -153,6 +153,15 @@ class DataStore:
self.requested_entry_index = entry
yield self.entries[entry]
def get_next_entry_id(self, entry_id):
index = [e.id for e in self.entries].index(entry_id) + 1
return self.entries[index].id
def get_previous_entry_id(self, entry_id):
index = [e.id for e in self.entries].index(entry_id) - 1
return self.entries[index].id
def get_entries(self, reverse=False):
self.requested_entry_index = 0 if not reverse else len(self.entries) - 1
......@@ -189,42 +198,42 @@ class DataStore:
return self.entries[self.requested_entry_index].date.minute
def get_entry_date(self, argv=list()):
return self.entries[self.requested_entry_index].date.strftime(self.blog_configuration["dateFormat"])
return self.entries[self.requested_entry_index].date.strftime(self.blog_configuration["date_format"])
def get_entry_date_url(self, argv=list()):
return self.entries[self.requested_entry_index].date.strftime(self.blog_configuration["path"]["datesDirectoryName"])
return self.entries[self.requested_entry_index].date.strftime(self.blog_configuration["path"]["dates_directory_name"])
def get_entry_url(self, argv=list()):
return self.blog_configuration["path"]["entryFileName"].format({
"entryId" : self.entries[self.requested_entry_index].id
return self.blog_configuration["path"]["entry_file_name"].format(**{
"entry_id" : self.entries[self.requested_entry_index].id
})
def get_author_name(self, argv=list()):
return self.blog_configuration["authorName"]
return self.blog_configuration["author_name"]
def get_blog_name(self, argv=list()):
return self.blog_configuration["blogName"]
return self.blog_configuration["blog_name"]
def get_blog_description(self, argv=list()):
return self.blog_configuration["blogDescription"]
return self.blog_configuration["blog_description"]
def get_blog_keywords(self, argv=list()):
return self.blog_configuration["blogKeywords"]
return self.blog_configuration["blog_keywords"]
def get_author_description(self, argv=list()):
return self.blog_configuration["authorDescription"]
return self.blog_configuration["author_description"]
def get_blog_license(self, argv=list()):
return self.blog_configuration["license"]
def get_blog_url(self, argv=list()):
return self.blog_configuration["blogUrl"]
return self.blog_configuration["blog_url"]
def get_blog_language(self, argv=list()):
return self.blog_configuration["blogLanguage"]
return self.blog_configuration["blog_language"]
def get_author_email(self, argv=list()):
return self.blog_configuration["authorEmail"]
return self.blog_configuration["author_email"]
def for_blog_dates(self, argv):
return merge(self.blog_dates, argv)
......
......@@ -113,7 +113,7 @@ class Entry:
self.categories_leaves = list()
self.categories_nodes_reference = list()
self.raw_categories = metadata["categories"].split(',')
self.raw_categories = [ c.strip() for c in metadata["categories"].split(',')]
try:
for category in self.raw_categories:
category_leaf = category.split(' > ')[-1].strip()
......
......@@ -182,6 +182,8 @@ 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(
......
......@@ -30,13 +30,12 @@ class Thread:
def __init__(self, prompt, datastore, theme, patterns):
# Notify wich thread is processed
notify(prompt)
self.entries_per_page = int(datastore.blog_configuration["entriesPerPages"])
self.entries_per_page = int(datastore.blog_configuration["entries_per_pages"])
# Setup useful data
self.theme = theme
self.current_page = 0
self.datastore = datastore
# Setup pattern processor
self.processor = Processor()
for pattern_name in patterns.keys():
......@@ -47,10 +46,11 @@ class Thread:
self.processor.set_function(pattern_name, patterns[pattern_name])
def return_page_around(self, string, destination_page_number, filename):
return string.format({
"destinationPage":destination_page_number,
"destinationPageUrl":filename,
"entryName" : self.entry_name
return string.format(**{
"destination_page":destination_page_number,
"destination_page_url":filename,
"entry_name" : self.entry_name,
"entry_id": self.entry_id
})
......@@ -76,8 +76,7 @@ class Thread:
def get_next_page(self,argv=list()):
if self.current_page < len(self.pages) - 1:
destination_page_number = str(self.current_page + 1)
''' Must catch KeyError exception '''
filename = self.filename.format({"pageNumber":destination_page_number})
filename = self.filename.format(**{"page_number":destination_page_number,"entry_id":self.datastore.get_next_entry_id(self.entry_id)})
return self.return_page_around(argv[0], destination_page_number, filename)
else:
......@@ -88,12 +87,10 @@ class Thread:
if self.current_page > 0:
destination_page_number = str(self.current_page - 1)
if self.current_page == 1:
''' Must catch KeyError exception '''
filename = self.filename.format(page_number="")
filename = self.filename.format(**{"page_number":"","entry_id": self.datastore.get_previous_entry_id(self.entry_id)})
else:
''' Must catch KeyError exception '''
filename = self.filename.format(page_number=destination_page_number)
filename = self.filename.format(**{"page_number":destination_page_number,"entry_id":self.datastore.get_previous_entry_id(self.entry_id)})
return self.return_page_around(argv[0], destination_page_number, filename)
......@@ -113,9 +110,9 @@ class Thread:
for page in self.pages:
if (not page_number < self.current_page - self.pages_count) and (not page_number > self.current_page + self.pages_count):
output += string.format(
{
"pageNumber":str(page_number),
"pageUrl": self.filename.format({"pageNumber": (str() if page_number == 0 else page_number) })
**{
"page_number":str(page_number),
"page_url": self.filename.format(**{"page_number": (str() if page_number == 0 else page_number) })
}
) + separator
......@@ -134,15 +131,15 @@ class Thread:
def format_filename(self, value):
try:
if value == 0:
return self.filename.format({
'entryId':value,
'pageNumber':''
return self.filename.format(**{
'entry_id':value,
'page_number':''
})
else:
return self.filename.format({
'entryId':value,
'pageNumber':value
return self.filename.format(**{
'entry_id':value,
'page_number':value
})
except KeyError as e:
......@@ -158,6 +155,8 @@ class Thread:
columns_counter = 0
columns = [ '' for i in range(0, columns_number) ]
for entry in page:
self.entry_name = entry.title
self.entry_id = entry.id
columns[columns_counter] += ''.join(self.processor.batch_process(entry.html_wrapper.above, entry.filename).sub_strings)
if entry.html_wrapper.required_content_pattern == ".:GetEntryPreview:.":
columns[columns_counter] += ''.join(self.processor.batch_process(entry.preview, entry.filename,).sub_strings)
......@@ -195,3 +194,4 @@ class Thread:
stream.close()
page_number += 1
self.current_page = page_number
......@@ -26,7 +26,7 @@ class CategoriesThread(Thread):
def __init__(self, prompt, datastore, theme, patterns):
super().__init__(prompt, datastore, theme, patterns)
self.filename = self.datastore.blog_configuration["path"]["indexFileName"]
self.filename = self.datastore.blog_configuration["path"]["index_file_name"]
self.entryname = str()
self.relative_origin = "../"
self.in_thread = True
......@@ -53,7 +53,7 @@ class CategoriesThread(Thread):
pass
entries = [self.datastore.entries[entry_index] for entry_index in node.related_to]
self.organize_entries( entries[::-1] if self.datastore.blog_configuration["reverseThreadOrder"] else entries )
self.organize_entries( entries[::-1] if self.datastore.blog_configuration["reverse_thread_order"] else entries )
super().do()
......
......@@ -26,7 +26,7 @@ class DatesThread(Thread):
def __init__(self, prompt, datastore, theme, patterns):
super().__init__(prompt, datastore, theme, patterns)
self.filename = self.datastore.blog_configuration["path"]["indexFileName"]
self.filename = self.datastore.blog_configuration["path"]["index_file_name"]
self.entry_name = str()
self.relative_origin = "../"
self.in_thread = True
......@@ -39,7 +39,7 @@ class DatesThread(Thread):
self.organize_entries([
entry for entry in self.datastore.get_entries_for_given_date(
thread.value,
self.datastore.blog_configuration["reverseThreadOrder"]
self.datastore.blog_configuration["reverse_thread_order"]
)
])
......
......@@ -28,11 +28,11 @@ class EntriesThread(Thread):
self.organize_entries([
entry for entry in datastore.get_entries(
datastore.blog_configuration["reverseThreadOrder"]
datastore.blog_configuration["reverse_thread_order"]
)
])
self.filename = self.datastore.blog_configuration["path"]["entryFileName"]
self.filename = self.datastore.blog_configuration["path"]["entry_file_name"]
self.entry_name = str()
self.relative_origin = str()
self.export_path = "blog/"
......
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