Commit 0ea2b1bb authored by Denis Salem's avatar Denis Salem
Browse files

wip on threads disabling

parent a7bed578
var VENC_INFINITE_SCROLL = {
queue: 0,
hideVenCNavigation: true,
pageOffset : 0,
interval : 250,
xmlhttp : Object,
timer: Object,
imageDefaultSetup: function(img) {},
entryDefaultSetup: function(entry) {
entry.style.opacity = "0.0";
},
onLoadImage: function(img) {},
onLoadEntry: function(entry){
entry.style.transition = "opacity 0.5s ease";
entry.style.opacity = "1.0";
},
loading : function() {
try {
document.getElementById("__VENC_LOADING__").style.opacity = "1";
}
catch (e) {
console.log("VenC: There is no __VENC_LOADING__ element.");
}
},
idle : function() {
try {
document.getElementById("__VENC_LOADING__").style.opacity = "0";
}
catch (e) {
console.log("VenC: There is no __VENC_LOADING__ element.");
}
},
initPageOffset : function() {
currentFilename = this.currentLocation;
if (currentFilename == '' | currentFilename == "index.html")
currentFilename = '0';
else if (currentFilename.replace( /[.html0123456789]+/g, '') != "index") {
return;
}
this.pageOffset = parseInt(currentFilename.replace( /^\D+/g, '').replace( /[.html]+/g,''))+1;
},
pushColumns : function() {
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
this.xmlhttp = new XMLHttpRequest();
}
else { // code for IE6, IE5
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
this.xmlhttp.onreadystatechange = this.ajax;
this.xmlhttp.open("GET","index"+this.pageOffset+".html",true);
this.pageOffset++;
this.xmlhttp.send();
},
dontWait: false,
currentLocation : Object,
ajax : Object
};
function VENC_INFINITE_SCROLL_AJAX() {
if (VENC_INFINITE_SCROLL.xmlhttp.readyState == 4 && VENC_INFINITE_SCROLL.xmlhttp.status == 200) {
xmlDoc = document.implementation.createHTMLDocument('');
xmlDoc.body.innerHTML = VENC_INFINITE_SCROLL.xmlhttp.responseText;
currentColumns = document.getElementsByClassName("__VENC_COLUMN__");
newColumns = xmlDoc.getElementsByClassName("__VENC_COLUMN__");
for (i=0; i < currentColumns.length; i++) {
newEntries = newColumns[i].getElementsByClassName("entry");
entriesClones = Array();
for (j=0; j < newEntries.length; j++) {
entriesClones.push( newEntries[j].cloneNode(true));
}
for(j=0; j < entriesClones.length; j++) {
VENC_INFINITE_SCROLL.entryDefaultSetup(entriesClones[j]);
images = entriesClones[j].getElementsByTagName("img");
if (images.length == 0) {
VENC_INFINITE_SCROLL.onLoadEntry(entriesClones[j]);
}
else {
for (k=0; k < images.length; k++) {
VENC_INFINITE_SCROLL.queue++;
VENC_INFINITE_SCROLL.imageDefaultSetup(images[k]);
images[k].loaded = false;
images[k].onload = function(e) {
this.loaded = true;
VENC_INFINITE_SCROLL.queue--;
VENC_INFINITE_SCROLL.onLoadImage(this);
for(l = 0; l < images.lenght; l) {
if (images[l].loaded == false) {
return;
}
}
VENC_INFINITE_SCROLL.onLoadEntry(this.closest(".entry"));
}
d = new Date()
images[k].src = images[k].src+"?uglyWorkAround="+d.getTime();
}
}
currentColumns[i].appendChild(entriesClones[j]);
}
}
}
};
function VENC_INFINITE_SCROLL_RUN() {
if (VENC_INFINITE_SCROLL.queue == 0) {
VENC_INFINITE_SCROLL.idle();
}
else {
VENC_INFINITE_SCROLL.loading();
}
currentColumns = document.getElementsByClassName("__VENC_COLUMN__");
viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
for (i=0; i < currentColumns.length; i++) {
if (currentColumns[i].clientHeight <= viewPortHeight + window.pageYOffset) {
if ((VENC_INFINITE_SCROLL.queue == 0 || VENC_INFINITE_SCROLL.dontWait) && (VENC_INFINITE_SCROLL.currentLocation.replace( /[.html0123456789]+/g, '') == "index" || VENC_INFINITE_SCROLL.currentLocation == "")) {
VENC_INFINITE_SCROLL.pushColumns();
return 1;
}
}
}
return 0;
};
function VENC_INFINITE_SCROLL_ON_LOAD() {
VENC_INFINITE_SCROLL.currentLocation = window.location.pathname.split('/')[window.location.pathname.split('/').length-1]
VENC_INFINITE_SCROLL.initPageOffset()
if (VENC_INFINITE_SCROLL.hideVenCNavigation && (VENC_INFINITE_SCROLL.currentLocation.replace( /[.html0123456789]+/g, '') == "index" || VENC_INFINITE_SCROLL.currentLocation == "")) {
try {
document.getElementById("__VENC_NAVIGATION__").setAttribute("style","display: none;");
}
catch (e) {
console.log("VenC: There is no __VENC_NAVIGATION__ element.");
}
}
VENC_INFINITE_SCROLL.ajax = VENC_INFINITE_SCROLL_AJAX;
VENC_INFINITE_SCROLL.timer = setInterval(VENC_INFINITE_SCROLL_RUN, VENC_INFINITE_SCROLL.interval);
};
/***************/
/* G L O B A L */
/***************/
body, html
{margin: 0px;
font-family: sans;
font-weight: lighter;
background-color: white;}
strong
{font-weight: bold;}
a
{outline: none;
color: black;
text-decoration: none;}
h1
{font-family: sans;
font-size: 3em;
letter-spacing: 10px;
text-transform: uppercase;
font-weight: lighter;}
/***************/
/* H E A D E R */
/***************/
#banner
{width: 90%;}
header h2
{font-size: 0.8em;
font-weight: lighter;
margin: 0px;
opacity: 0.5;}
header
{text-align: center;
color: black;
text-align: center;}
header ul
{margin: 0px;
display: inline-block;
list-style-type: none;
padding: 0px;}
header li
{margin: 1em;
font-size: 1.25em;
display: inline-block;}
header a
{opacity: 0.8;
color: black;
transition: 0.5s ease all;}
header a:hover
{opacity:1.0;}
#archives li
{margin: 0.5em;
font-size: 0.8em;}
/*************/
/* E N T R Y */
/*************/
.entry
{font-size: 1em;
width: 700px;
margin: auto;
text-align: justify;
transition: 1s ease all;
overflow: hidden;}
.entry img
{max-width: 100%;
display: block;
margin: auto;
margin-top: 1em;
margin-bottom: 1em;}
.entry a {
text-decoration: underline;
}
.entry em {
color: grey;
}
.permalink a
{color: black;
font-size: 1em;
text-decoration: none;}
.permalink
{margin: 0px;
margin-top: 1em;
margin-bottom: 1em;
text-align: center;}
.permalink p
{font-size: 1em;
letter-spacing: 5px;
opacity: 0.5;}
.entry pre
{overflow: scroll;}
/***************/
/* F O O T E R */
/***************/
footer
{padding: 1em;
font-size: 2em;
text-align: center;}
footer #pagesList
{list-style-type: none;
display:inline-block;
text-align: center;
margin: 0px;
padding-left: 3px;}
footer a
{color: black;}
footer #pagesList li, #previous, #next
{display: inline-block;}
@media (max-width: 360px) {
header li
{display: block;}
#archivesHeader
{display: none;}
#archives
{display: none;}
.entry
{width:95%;
margin-left: 2.5%;}
.permalink a
{font-size: 0.66em;
letter-spacing: 0px;}
footer
{font-size: 1.25em;}
}
<div class="entry .:GetEntryMetadataIfExists::CSS:." id="entry.:GetEntryID:." data-venc-tags=".:ForEntryTags::{0[tag]}:: :.">
<div class="permalink">
<h1><a href=".:GetRelativeOrigin:.entry.:GetEntryID:..html">.:GetEntryTitle:.</a></h1>
<p>.:GetEntryDate:.</p>
</div>
.:GetEntryContent:.
</div>
</div>
<footer id="__VENC_NAVIGATION__">
.: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>
<!DOCTYPE html>
<html lang=".:GetBlogLanguage:.">
<head>
<title>.:GetBlogName:.</title>
<meta name="generator" content="VenC" />
<meta name="keywords" content=".:GetBlogKeywords:." />
<meta name="description" content=".:GetBlogDescription:."/>
<meta charset="utf-8" />
<script type="text/javascript" src=".:GetRelativeOrigin:.VenC-Infinite-Scroll-1.0.0.js"></script>
<script type="text/javascript">
window.onload = VENC_INFINITE_SCROLL_ON_LOAD;
</script>
<link rel="alternate" type="application/rss+xml" title=".:GetBlogName:." href="feed.xml" />
<link rel="stylesheet" href=".:GetRelativeOrigin:.style.css" type="text/css" />
.:GetStyleSheets:.
.:IfInThread::<link rel="stylesheet" href=".:GetRelativeOrigin:.styleThread.css" type="text/css" />::<link rel="stylesheet" href=".:GetRelativeOrigin:.styleEntry.css" type="text/css" />:.
</head>
<body>
<header>
<h1>
<a href=".:IfInThread:: ../.:GetRelativeOrigin:. :: index.html :. ">
<img id="banner" src=".:GetRelativeOrigin:..:GetBlogMetadataIfExists::banner:." alt=".:GetBlogName:." title=".:GetBlogName:." />
</a>
</h1>
<h2>CATEGORIES</h2>
<div id="categories">
.:RecursiveFor::BlogCategories::<ul>::<li><a href="{0[relativeOrigin]}{0[categoryPath]}" title="{0[count]} publications">{0[item]}</a>::</li>::</ul>:.
</div>
<h2 id="archivesHeader">ARCHIVES</h2>
<ul id="archives">.:ForBlogDates::<li><a href="{0[dateUrl]}" title="{0[count]} publications">{0[date]}</a></li>:: :.</ul>
<div id="__VENC_LOADING__"></div>
</header>
<div id="__VENC_THREAD__">
<item>
<title>.:GetEntryTitle:.</title>
<link>.:GetBlogURL:..:GetEntryURL:.</link>
<guid isPermaLink="true">.:GetBlogURL:..:GetEntryURL:.</guid>
<description><![CDATA[.:GetEntryContent:.]]></description>
</item>
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href=".:GetBlogURL:..:GetRelativeLocation:.feed.xml" rel="self" type="application/rss+xml" />
<title>.:GetBlogName:.</title>
<link>.:GetBlogURL:.</link>
<description><![CDATA[.:GetBlogDescription:.]]></description>
......@@ -121,11 +121,11 @@
DONE | Support for video.
DONE | Support for audio.
DONE | Optimise entries access with linked list.
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).
DONE | Add more specific pattern to detect location (IfInCategories,IfInArchives,IfInFirstPage, etc).
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 | Export empty blog.
TODO | Open with navigator manual.
TODO | Add relevant templates for themes.
TODO | Add categories tree in entry.
......@@ -140,5 +140,6 @@
TODO | Fix unit test.
# version 2.x.x
TODO | Add docutils reStructuredText parser settings override.
TODO | Decrease halt_level to render reStructuredText even if errors occurs.
......@@ -90,6 +90,11 @@ non_contextual_pattern_names_ml = {
contextual_pattern_names = {
"GetRelativeOrigin" : "get_relative_origin",
"IfInThread" : "if_in_thread",
"IfInArchives" : "if_in_archives",
"IfInCategories" : "if_in_categories",
"IfInFirstPage" : "if_in_first_page",
"IfInLastPage" : "if_in_last_page",
"IfInEntryID" : "if_in_entry_id",
"GetRelativeLocation" : "get_relative_location",
"GetNextPage" : "get_next_page",
"GetPreviousPage" : "get_previous_page",
......@@ -170,18 +175,24 @@ def export_blog(argv=list()):
thread = MainThread(messages.export_main_thread, datastore, theme, contextual_pattern_names)
thread.do()
thread = DatesThread(messages.export_archives, datastore, theme, contextual_pattern_names)
thread.do()
thread = CategoriesThread(messages.export_categories, datastore, theme, contextual_pattern_names)
thread.do()
thread = EntriesThread(messages.export_categories, datastore, theme, contextual_pattern_names)
thread.do()
if not datastore.blog_configuration["disable_archives"]:
thread = DatesThread(messages.export_archives, datastore, theme, contextual_pattern_names)
thread.do()
if not datastore.blog_configuration["disable_categories"]:
thread = CategoriesThread(messages.export_categories, datastore, theme, contextual_pattern_names)
thread.do()
if not datastore.blog_configuration["disable_single_entries"]:
thread = EntriesThread(messages.export_single_entries, datastore, theme, contextual_pattern_names)
thread.do()
# Copy assets and extra files
code_highlight.export_style_sheets()
copy_recursively("extra/","blog/")
copy_recursively("theme/assets/","blog/")
copy_recursively(theme_folder+"assets/","blog/")
def copy_recursively(src, dest):
......
......@@ -107,6 +107,10 @@ def new_blog(argv):
die(Messages.missingParams.format("--new-blog"))
default_configuration = {"blog_name": messages.blog_name,
"disable_threads": "",
"disable_archives": False,
"disable_categories": False,
"disable_single_entries": False,
"text_editor": "nano",
"date_format": "%A %d. %B %Y",
"author_name": messages.your_name,
......
......@@ -45,7 +45,11 @@ def get_blog_configuration():
"columns",
"rss_thread_lenght",
"reverse_thread_order",
"markup_language"
"markup_language",
"disable_threads",
"disable_archives",
"disable_categories",
"disable_single_entries"
]
everything_is_okay = True
......
......@@ -49,6 +49,7 @@ class Messages:
possible_malformed_entry="Possible malformed entry {0}. {1} Abort."
possible_malformed_blog_configuration="Possible malformed blog configuration. Abort."
blog_recompilation="Recompilation of your blog locally..."
export_single_entries="Exporting local single entries..."
export_archives="Exporting local entries sorted by dates..."
export_main_thread="Exporting local main entries thread."
export_main_thread_rss="Exporting local main RSS feed entries."
......
......@@ -48,6 +48,7 @@ class Messages:
possible_malformed_entry="La publication {0} est probablement mal formée... {1} Abandon."
possible_malformed_blog_configuration="Le fichier de configuration du blog est probablement mal formée... Abandon."
blog_recompilation="Recompilation du blog locale..."
export_single_entries="Exportation locale des publications individuelles..."
export_archives="Exportation locale des publications triées par dates..."
export_main_thread="Exportation locale du fil de publications principal."
export_main_rhread_rss="Exportation locale du flux RSS du fil de publications principal."
......@@ -84,3 +85,4 @@ class Messages:
tex_math_error = "Chaine mal formé ou balise non supporté par latex2mathml."
missing_separator_in_entry = "Il manque le séparateur {0}."
......@@ -126,7 +126,29 @@ class Thread:
return output[:-len(separator)]
def if_in_first_page(self, argv):
if self.current_page == 0:
return argv[0]
else:
return argv[1]
def if_in_last_page(self, argv):
if self.current_page == len(self.pages) -1:
return argv[0]
else:
return argv[1]
def if_in_entry_id(self, argv):
return argv[2]
def if_in_categories(self, argv):
return argv[1]
def if_in_archives(self, argv):
return argv[1]
def if_in_thread(self, argv):
if self.in_thread:
return argv[0]
......@@ -154,49 +176,61 @@ class Thread:
# Must be called in child class
def do(self):
page_number = 0
for page in self.pages:
if len(self.pages) == 0:
output = ''.join(self.processor.batch_process(self.theme.header, "header.html").sub_strings)
columns_number = self.datastore.blog_configuration["columns"]
columns_counter = 0
columns = [ '' for i in range(0, columns_number) ]
for entry in page:
self.current_entry = entry
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)
elif entry.html_wrapper.required_content_pattern == ".:PreviewIfInThreadElseContent:." and self.in_thread:
columns[columns_counter] += ''.join(self.processor.batch_process(entry.preview, entry.filename,).sub_strings)
else:
columns[columns_counter] += ''.join(self.processor.batch_process(entry.content, entry.filename,).sub_strings)
columns[columns_counter] += ''.join(self.processor.batch_process(entry.html_wrapper.below, entry.filename).sub_strings)
columns_counter +=1
if columns_counter >= columns_number:
columns_counter = 0
columns_counter = 0
for column in columns:
output += '<div id="__VENC_COLUMN_'+str(columns_counter)+'__" class="__VENC_COLUMN__">'+column+'</div>'
output += ''.join(self.processor.batch_process(self.theme.footer, "footer.html").sub_strings)
if self.in_thread:
format_value = page_number
else:
format_value = page[0].id
stream = codecs.open(
self.export_path + self.format_filename(format_value),
self.export_path + self.format_filename(0),
'w',
encoding="utf-8"
)
stream.write(output)
stream.close()
else:
for page in self.pages:
output = ''.join(self.processor.batch_process(self.theme.header, "header.html").sub_strings)
columns_number = self.datastore.blog_configuration["columns"]
columns_counter = 0
columns = [ '' for i in range(0, columns_number) ]
for entry in page:
self.current_entry = entry
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)
elif entry.html_wrapper.required_content_pattern == ".:PreviewIfInThreadElseContent:." and self.in_thread:
columns[columns_counter] += ''.join(self.processor.batch_process(entry.preview, entry.filename,).sub_strings)
else:
columns[columns_counter] += ''.join(self.processor.batch_process(entry.content, entry.filename,).sub_strings)
page_number += 1
self.current_page = page_number
columns[columns_counter] += ''.join(self.processor.batch_process(entry.html_wrapper.below, entry.filename).sub_strings)
columns_counter +=1
if columns_counter >= columns_number:
columns_counter = 0
columns_counter = 0
for column in columns:
output += '<div id="__VENC_COLUMN_'+str(columns_counter)+'__" class="__VENC_COLUMN__">'+column+'</div>'
output += ''.join(self.processor.batch_process(self.theme.footer, "footer.html").sub_strings)
if self.in_thread:
format_value = page_number