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

Rework on chapters engine.

parent 84cfa7c6
......@@ -15,6 +15,7 @@ code_highlight_css_override: true
markup_language: 'Markdown'
path:
category_directory_name: '{category}'
chapter_directory_name: '{chapter_name}'
dates_directory_name: '%m-%Y'
entry_file_name: index.html
ftp: Chemin absolu de votre blog sur l'hôte FTP.
......@@ -23,7 +24,8 @@ path:
atom_file_name: atom_feed.xml
dates_sub_folders: ""
categories_sub_folders: ""
entries_sub_folders: "{entry_title}"
entries_sub_folders: ""
chapters_sub_folders: "chapters/{chapter_name}"
reverse_thread_order: false
feed_lenght: 5
text_editor: gvim
......@@ -32,10 +34,12 @@ disable_atom_feed: true
disable_main_thread: true
disable_threads: ""
disable_archives: true
disable_chapters: false
disable_categories: true
disable_single_entries: false
disable_single_entries: true
banner: 'https://download.tuxfamily.org/dsalem/img/2017_-_Denis_Salem_-_CC_By_SA_-_VenC-logo.svg'
path_encoding: 'windows-1252'
server_port: 8888
sort_by: 'chapter'
enable_jsonld: True
enable_jsonp: False
......@@ -66,11 +66,4 @@
.venc_source_Yaml .vg { color: #19177C } /* Name.Variable.Global */
.venc_source_Yaml .vi { color: #19177C } /* Name.Variable.Instance */
.venc_source_Yaml .vm { color: #19177C } /* Name.Variable.Magic */
.venc_source_Yaml .il { color: #666666 } /* Literal.Number.Integer.Long */
.venc_source_Yamltable {width: 100%; display: block;}
.venc_source_Yamltable tr {width: 100%; display: block;}
.venc_source_Yamltable tbody {width: 100%; display: block;}
.venc_source_Yamltable .linenos {width: 4%; display: inline-block;vertical-align: top;}
.venc_source_Yamltable .code {width: 95%; display: inline-block;vertical-align: top;}
.venc_source_Yamltable td pre {vertical-align: top; overflow: hidden; overflow-x: scroll;}
.venc_source_Yaml pre {overflow: hidden; overflow-x: scroll;}
\ No newline at end of file
.venc_source_Yaml .il { color: #666666 } /* Literal.Number.Integer.Long */
\ No newline at end of file
......@@ -115,6 +115,7 @@ new_keys = {
"disable_main_thread": False,
"disable_archives": False,
"disable_categories": False,
"disable_chapters": True,
"disable_single_entries": False,
"path_encoding":"utf-8",
"code_highlight_css_override":False,
......@@ -130,6 +131,8 @@ new_keys = {
new_path_keys = {
"atom_file_name": "atom_feed.xml",
"entries_sub_folders":"",
"chapters_sub_folders":"chapters",
"chapter_directory_name": "{chapter_name}",
"categories_sub_folders":"",
"dates_sub_folders":""
}
......
......@@ -189,6 +189,11 @@ def export_blog(argv=list()):
thread = EntriesThread(messages.export_single_entries, datastore, theme, patterns_map)
thread.do()
if not datastore.blog_configuration["disable_chapters"]:
from venc2.threads.chapters import ChaptersThread
thread = ChaptersThread(messages.export_chapters, datastore, theme, patterns_map)
thread.do()
# Copy assets and extra files
notify('└─ '+messages.copy_assets_and_extra_files)
code_highlight.export_style_sheets()
......
......@@ -125,6 +125,7 @@ def new_blog(argv):
"disable_threads": "",
"disable_archives": False,
"disable_categories": False,
"disable_chapters": True,
"disable_single_entries": False,
"disable_main_thread": False,
"disable_rss_feed": False,
......@@ -146,8 +147,10 @@ def new_blog(argv):
"entries_sub_folders": "",
"categories_sub_folders": "",
"dates_sub_folders": "",
"chapters_sub_folders": "chapters",
"index_file_name": "index{page_number}.html",
"category_directory_name": "{category}",
"chapter_directory_name": "{chapter_name}",
"dates_directory_name": "%Y-%m",
"entry_file_name": "entry{entry_id}.html",
"rss_file_name": "rss.xml",
......
......@@ -22,7 +22,7 @@ import os
import datetime
import json
import urllib.parse
from urllib.parse import quote as urllib_parse_quote
from venc2.datastore.configuration import get_blog_configuration
from venc2.datastore.entry import yield_entries_content
......@@ -57,6 +57,7 @@ class DataStore:
self.enable_jsonld = self.blog_configuration["enable_jsonld"]
self.enable_jsonp = self.blog_configuration["enable_jsonp"]
self.blog_url = self.blog_configuration["blog_url"]
self.path_encoding = self.blog_configuration["path_encoding"]
self.disable_threads = [thread_name.strip() for thread_name in self.blog_configuration["disable_threads"].split(',')]
self.entries = list()
self.entries_per_dates = list()
......@@ -95,7 +96,7 @@ class DataStore:
self.blog_configuration["path"],
jsonld_callback,
self.blog_configuration["path"]["dates_directory_name"],
self.blog_configuration["path_encoding"]
self.path_encoding
))
except MalformedPatterns as e:
......@@ -123,17 +124,18 @@ class DataStore:
# Update entriesPerCategories
try:
sub_folders = urllib.parse.quote(self.blog_configuration["path"]["categories_sub_folders"]+'/', encoding=self.blog_configuration["path_encoding"])
sub_folders = urllib_parse_quote(self.blog_configuration["path"]["categories_sub_folders"]+'/', encoding=self.path_encoding)
except UnicodeEncodeError as e:
sub_folders = self.blog_configuration["path"]["categories_sub_folders"]+'/'
notify("\"{0}\": ".format(sub_folders)+str(e), color="YELLOW")
sub_folders = sub_folders if sub_folders != '/' else ''
build_categories_tree(entry_index, current_entry.raw_categories, self.entries_per_categories, self.categories_leaves, self.max_category_weight, self.set_max_category_weight, encoding=self.blog_configuration["path_encoding"], sub_folders=sub_folders)
build_categories_tree(entry_index, current_entry.raw_categories, self.entries_per_categories, self.categories_leaves, self.max_category_weight, self.set_max_category_weight, encoding=self.path_encoding, sub_folders=sub_folders)
self.update_chapters(current_entry)
# build chapters index
chapters_sub_folders = self.blog_configuration["path"]["chapters_sub_folders"]
for chapter in sorted(self.raw_chapters.keys()):
top = self.chapters_index
index = ''
......@@ -154,20 +156,22 @@ class DataStore:
except StopIteration:
try:
top.append(
Chapter(index, self.raw_chapters[index][1], self.raw_chapters[index][2])
Chapter(index, self.raw_chapters[index])
)
except KeyError:
top.append(
Chapter(index, '', '')
)
top = top[-1].sub_chapters
# Setup BlogArchives Data
self.blog_dates = list()
""" Should use encoding for path value as well """
for node in self.entries_per_dates:
try:
sub_folders = urllib.parse.quote(self.blog_configuration["path"]["dates_sub_folders"]+'/', encoding=self.blog_configuration["path_encoding"])
sub_folders = urllib_parse_quote(self.blog_configuration["path"]["dates_sub_folders"]+'/', encoding=self.path_encoding)
except UnicodeEncodeError as e:
sub_folders = self.blog_configuration["path"]["dates_sub_folders"]+'/'
......@@ -388,19 +392,32 @@ class DataStore:
lo, io, ic, lc = argv
if top == []:
return ''
path_encoding = self.path_encoding
output = lo.format(**{"level" :level})
for sub_chapters in top:
chapter_sub_folder = self.blog_configuration["path"]["chapters_sub_folders"]
chapter_folder_name = self.blog_configuration["path"]["chapter_directory_name"]
for sub_chapter in top:
try:
path = (chapter_sub_folder+'/'+chapter_folder_name).format(**{
"chapter_name" : sub_chapter.entry.title,
"chapter_index" : sub_chapter.index
})
except KeyError as e:
print("Unknown variable", e)
output += io.format(**{
"index": sub_chapters.index,
"title": sub_chapters.title,
"path": sub_chapters.path,
"index": sub_chapter.index,
"title": sub_chapter.entry.title,
"path": ".:GetRelativeOrigin:."+urllib_parse_quote(path, encoding=path_encoding),
"level": level
})
output += self.build_html_chapters(argv, sub_chapters.sub_chapters, level+1)
output += self.build_html_chapters(argv, sub_chapter.sub_chapters, level+1)
output += ic
output += lc
return output
def update_chapters(self, entry):
......@@ -424,7 +441,7 @@ class DataStore:
chapter
))
else:
self.raw_chapters[chapter] = (entry.id, entry.title, entry.url)
self.raw_chapters[chapter] = entry
def sort(self, entry):
try:
......
......@@ -50,6 +50,7 @@ def get_blog_configuration():
"disable_main_thread",
"disable_archives",
"disable_categories",
"disable_chapters",
"disable_single_entries",
"path_encoding",
"code_highlight_css_override",
......@@ -70,6 +71,7 @@ def get_blog_configuration():
mandatory_fields = [
"index_file_name",
"category_directory_name",
"chapter_directory_name",
"dates_directory_name",
"entry_file_name",
"rss_file_name",
......@@ -77,7 +79,8 @@ def get_blog_configuration():
"ftp",
"entries_sub_folders",
"categories_sub_folders",
"dates_sub_folders"
"dates_sub_folders",
"chapters_sub_folders",
]
for field in mandatory_fields:
......
......@@ -23,12 +23,10 @@ import urllib.parse
from venc2.prompt import notify
class Chapter:
def __init__(self, index, title, path):
def __init__(self, index, entry):
self.sub_chapters = []
self.index = index
self.title = title
self.path = path
self.entry = entry
class MetadataNode:
def __init__(self, value, entry_index):
......
......@@ -53,6 +53,7 @@ class Messages:
export_main_thread="Exporting local main entries thread."
export_main_thread_rss="Exporting local main RSS feed entries."
export_categories="Exporting local entries grouped by categories..."
export_chapters="Exporting local chapters..."
export_categoriesRss="Exporting local entries RSS feed thread from category '{0}'."
missing_mandatory_field_in_entry="Field '{0}' in entry number {1} is missing."
for_unknown_value="For: Value {0} isn't defined."
......
......@@ -52,6 +52,7 @@ class Messages:
export_main_thread="Exportation locale du fil de publications principal."
export_main_rhread_rss="Exportation locale du flux RSS du fil de publications principal."
export_categories="Exportation locale des publications groupées par categories..."
export_chapters="Exportation locale des chapitres..."
export_categories_rss="Exportation locale du flux RSS du fil de publications de la categorie '{0}'."
missing_mandatory_field_in_entry="Le champ '{0}' dans l'entrée numéro {1} est manquant."
recursive_for_unknown_value="RecursiveFor: La valeur {0} n'existe pas."
......@@ -108,4 +109,3 @@ class Messages:
nothing_to_serv = "Rien à faire. Essayez venc -xb d'abord."
theme_has_no_description = "Ce thème n'a pas de description."
undefined_variable = "{0} n'est pas défini dans \"{1}\"."
......@@ -18,7 +18,6 @@
# along with VenC. If not, see <http://www.gnu.org/licenses/>.
import os
import urllib.parse
from venc2.prompt import notify
from venc2.threads import Thread
......
......@@ -30,11 +30,7 @@ class EntriesThread(Thread):
def __init__(self, prompt, datastore, theme, patterns_map):
super().__init__(prompt, datastore, theme, patterns_map)
self.entries_per_page = 1 #override value
self.organize_entries([
entry for entry in datastore.get_entries(
False
)
])
self.organize_entries(datastore.entries)
self.filename = self.datastore.blog_configuration["path"]["entry_file_name"]
self.sub_folders = self.datastore.blog_configuration["path"]["entries_sub_folders"]
......
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