Commit 9ab0d1b0 authored by Denis Salem's avatar Denis Salem
Browse files

done with atom/rss, add generation timestamp

parent 02567589
......@@ -27,13 +27,13 @@ path:
reverse_thread_order: false
feed_lenght: 5
text_editor: gvim
disable_rss_feed: False
disable_atom_feed: False
disable_main_thread: true
disable_rss_feed: false
disable_atom_feed: false
disable_main_thread: false
disable_threads: ""
disable_archives: true
disable_categories: false
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
......@@ -138,9 +138,10 @@
DONE | Serv page.
DONE | Replace python-markdown by markdown2.
DONE | Replace white spaces in url by dashes.
WIP | Add support for Atom feed.
TODO | Split unit-test and themes from main branch
DONE | Add support for Atom feed.
DONE | Add blog generation timestamp.
TODO | Support ForPage in entries thread.
TODO | Split unit-test and themes from main branch
TODO | Blacklist user defined patterns from entry.
TODO | Update command help with.
TODO | Open with navigator manual.
......@@ -148,7 +149,7 @@
TODO | Fix unit test.
TODO | Reorganize themes dependencies in setup (adding default templates, scripts, and pages to include).
TODO | Add relevant templates for themes.
WIP | fix FAQ https://stackoverflow.com/questions/14547631/python-locale-error-unsupported-locale-setting.
TODO | fix FAQ https://stackoverflow.com/questions/14547631/python-locale-error-unsupported-locale-setting.
WIP | fix FAQ latex2mathml is incomplete.
WIP | fix FAQ categories separator is ' > ', not '>'
WIP | fix FAQ subfolders must not start with '/'
......@@ -160,6 +161,8 @@
TODO | Add docutils reStructuredText parser settings override.
TODO | Decrease halt_level to render reStructuredText even if errors occurs.
TODO | Access {count} and {weight} from LeavesForEntrycategories.
TODO | Add Yaml comments in blog configuration
TODO | Catch invalid encoding at startup
TODO | Get formatted link to specified page/entry
TODO | Add Yaml comments in blog configuration.
TODO | Catch invalid encoding at startup.
TODO | Add nice 404 errors page.
TODO | Improve Feed.
TODO | Print out what's going on while FTP transfert.
......@@ -96,7 +96,8 @@ non_contextual_pattern_names_blog = {
non_contextual_pattern_names_datastore = {
**non_contextual_pattern_names_blog,
**non_contextual_pattern_names_entry,
"GetEmbedContent": "wrapper_embed_content"
"GetEmbedContent": "wrapper_embed_content",
"GetGenerationTimestamp":"get_generation_timestamp"
}
non_contextual_pattern_names_ml = {
......@@ -212,9 +213,6 @@ def export_blog(argv=list()):
if not datastore.blog_configuration["disable_single_entries"]:
thread = EntriesThread(messages.export_single_entries, datastore, theme, contextual_pattern_names, non_contextual_pattern_names_entry_keys)
thread.do()
if not datastore.blog_configuration["disable_rss_feed"]:
thread = FeedThread("RSS", datastore, theme, contextual_pattern_names, non_contextual_pattern_names_entry_keys, "rss")
thread.do()
# Copy assets and extra files
......
......@@ -20,6 +20,7 @@
import hashlib
import json
import os
import datetime
import urllib.parse
from venc2.datastore.configuration import get_blog_configuration
......@@ -51,6 +52,7 @@ class DataStore:
self.html_categories_tree = {}
self.html_categories_leaves = {}
self.html_blog_dates = {}
self.generation_timestamp = datetime.datetime.now()
''' Entry index is different from entry id '''
entry_index = 0
......@@ -106,6 +108,9 @@ class DataStore:
self.max_category_weight = value
return value
def get_generation_timestamp(self, argv):
return datetime.datetime.strftime(self.generation_timestamp, argv[0])
def get_blog_metadata(self, argv):
# if exception is raised it will be automatically be catch by processor.
return self.blog_configuration[argv[0]]
......
......@@ -94,3 +94,5 @@ class Messages:
server_port_is_invalid = "\"{0}\": is not a valid port number."
serving_blog = "Server is now running on port : {0}."
invalid_or_missing_metadata = "\"{0}\": Invalid value or missing metadata in entry \"{1}\"."
generating_rss = "Generating RSS feed..."
generating_atom = "Generating Atom feed..."
......@@ -92,5 +92,7 @@ class Messages:
server_port_is_invalid = "\"{0}\" n'est pas un numéro de port valide."
serving_blog = "Serveur actif sur le port : {0}."
invalid_or_missing_metadata = "\"{0}\": Valeur de meta-donnée invalide ou abstente dans la publication \"{1}\"."
generating_rss = "Génération du flux RSS..."
generating_atom = "Génération du flux Atom..."
......@@ -28,6 +28,7 @@ from venc2.patterns.processor import Processor
class Thread:
def __init__(self, prompt, datastore, theme, patterns, forbidden):
self.datastore = datastore
# Notify wich thread is processed
if prompt != "":
notify(prompt)
......@@ -45,9 +46,9 @@ class Thread:
self.content_type = "html"
self.column_opening = '<div id="__VENC_COLUMN_{0}__" class="__VENC_COLUMN__">'
self.column_closing = "</div>"
self.columns_number = self.datastore.blog_configuration["columns"]
self.current_page = 0
self.datastore = datastore
# Setup pattern processor
self.processor = Processor()
for pattern_name in patterns.keys():
......@@ -224,8 +225,6 @@ class Thread:
self.processor.forbidden = self.forbidden
self.output = ''.join(self.processor.batch_process(self.header, self.context_header).sub_strings)
self.processor.forbidden = []
self.columns_number = self.datastore.blog_configuration["columns"]
self.columns_counter = 0
self.columns = [ '' for i in range(0, self.columns_number) ]
......
......@@ -22,6 +22,7 @@ import urllib.parse
from venc2.helpers import notify
from venc2.threads import Thread
from venc2.threads.feed import FeedThread
class CategoriesThread(Thread):
def __init__(self, prompt, datastore, theme, patterns, forbidden):
......@@ -31,6 +32,11 @@ class CategoriesThread(Thread):
self.export_path = "blog/"+self.datastore.blog_configuration["path"]["categories_sub_folders"]+'/'
self.relative_origin = ""
self.in_thread = True
if not self.datastore.blog_configuration["disable_rss_feed"]:
self.rss_feed = FeedThread(datastore, theme, patterns, forbidden, "rss")
if not self.datastore.blog_configuration["disable_atom_feed"]:
self.atom_feed = FeedThread(datastore, theme, patterns, forbidden, "atom")
def if_in_categories(self, argv):
return argv[0].strip()
......@@ -49,17 +55,23 @@ class CategoriesThread(Thread):
self.export_path += str(node.value+'/').replace(' ','-')
self.relative_origin = ''.join([ '../' for f in self.export_path.split("/")[1:] if f != '' ]).replace("//",'/')
# Get entries
try:
os.makedirs(self.export_path)
except FileExistsError:
pass
# Get entries
entries = [self.datastore.entries[entry_index] for entry_index in node.related_to]
self.organize_entries( entries[::-1] if self.datastore.blog_configuration["reverse_thread_order"] else entries )
super().do()
entries = sorted(entries, key = lambda entry : entry.id, reverse=True)[0:self.datastore.blog_configuration["feed_lenght"]]
if not self.datastore.blog_configuration["disable_rss_feed"]:
self.rss_feed.do(entries, self.export_path, self.relative_origin)
if not self.datastore.blog_configuration["disable_atom_feed"]:
self.atom_feed.do(entries, self.export_path, self.relative_origin)
self.do(root=node.childs)
......
......@@ -18,26 +18,32 @@
# along with VenC. If not, see <http://www.gnu.org/licenses/>.
from venc2.threads import Thread
from venc2.helpers import notify
from venc2.l10n import messages
class FeedThread(Thread):
def __init__(self, prompt, datastore, theme, patterns, forbidden, feed_type):
super().__init__(prompt, datastore, theme, patterns, forbidden)
def __init__(self, datastore, theme, patterns, forbidden, feed_type):
super().__init__('', datastore, theme, patterns, forbidden)
self.footer = getattr(self.theme, feed_type+"_footer")
self.header = getattr(self.theme, feed_type+"_header")
self.entry = getattr(self.theme, feed_type+"_entry")
self.context_header = feed_type+"Header.xml"
self.context_footer = feed_type+"Footer.xml"
self.column_opening =''
self.column_closing =''
self.column_opening = ''
self.column_closing = ''
self.columns_number = 1
self.filename = self.datastore.blog_configuration["path"][feed_type+"_file_name"]
self.entries_per_page = self.datastore.blog_configuration["feed_lenght"]
self.export_path = "blog/"
self.relative_origin = ""
self.in_thread = True
self.content_type = feed_type
def do(self):
self.organize_entries([entry for entry in self.datastore.get_entries(True)][0:self.entries_per_page])
def do(self, entries, export_path, relative_origin):
notify(getattr(messages, "generating_"+self.content_type))
self.export_path = export_path
self.relative_origin = relative_origin
self.organize_entries(entries)
super().do()
......@@ -18,6 +18,7 @@
# along with VenC. If not, see <http://www.gnu.org/licenses/>.
from venc2.threads import Thread
from venc2.threads.feed import FeedThread
class MainThread(Thread):
def __init__(self, prompt, datastore, theme, patterns, forbidden):
......@@ -40,8 +41,28 @@ class MainThread(Thread):
self.relative_origin = str()
self.export_path = "blog/"
self.in_thread = True
if not self.datastore.blog_configuration["disable_rss_feed"]:
self.rss_feed = FeedThread(datastore, theme, patterns, forbidden, "rss")
if not self.datastore.blog_configuration["disable_atom_feed"]:
self.atom_feed = FeedThread(datastore, theme, patterns, forbidden, "atom")
def do(self):
super().do()
i = 0
entries = []
for entry in self.datastore.get_entries(True):
entries.append(entry)
i+=1
if i == self.datastore.blog_configuration["feed_lenght"]:
break
if not self.datastore.blog_configuration["disable_rss_feed"]:
self.rss_feed.do(entries, self.export_path, self.relative_origin)
if not self.datastore.blog_configuration["disable_atom_feed"]:
self.atom_feed.do(entries, self.export_path, self.relative_origin)
......
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