added RSS 2.0 at publish. RSS link in default footer. Some changes

This commit is contained in:
Cyrille L 2023-03-13 12:53:26 +01:00
parent 04303d8b2b
commit 78b4af6914
8 changed files with 168 additions and 46 deletions

View File

@ -100,6 +100,8 @@ domain_values = \
'www_sidebar', 'www_sidebar',
'www_metas', 'www_metas',
'www_footer', 'www_footer',
'www_rss',
'domain_rss',
'domain_footer_about', 'domain_footer_about',
'domain_active', 'domain_active',
) )

View File

@ -193,10 +193,53 @@ def create_domain(target):
'www_navbar = "%snavbar.html"\n'%srv_www_tpl + \ 'www_navbar = "%snavbar.html"\n'%srv_www_tpl + \
'www_sidebar = "%ssidebar.html"\n'%srv_www_tpl + \ 'www_sidebar = "%ssidebar.html"\n'%srv_www_tpl + \
'www_metas = "%smetas.html"\n'%srv_www_tpl + \ 'www_metas = "%smetas.html"\n'%srv_www_tpl + \
'www_footer = "%sfooter.html"\n'%srv_www_tpl 'www_footer = "%sfooter.html"'%srv_www_tpl
tyto.set_file(db.domain_conf, False, set_f) tyto.set_file(db.domain_conf, False, set_f)
# Get logo's website
#-------------------
try: domain_logo = db.domain_logo
except: domain_logo = 'logo.png'
ask = ''
try:
ask = input(' ├ logo filename ? {%s} '%domain_logo)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: domain_logo = ask
set_f = 'wip_logo = "%s%s"\n'%(srv_wip_tpl, domain_logo) + \
'www_logo = "%s%s"'%(srv_www_tpl, domain_logo)
tyto.set_file(db.domain_conf, False, set_f)
# RSS/Atom filename
#------------------
try: domain_rss = db.domain_rss
except: domain_rss = 'rss.xml'
ask = ''
try:
ask = input(' ├ Atom/RSS filename ? {%s} '%domain_rss)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask:
www_rss = ask
set_f = 'www_rss = "%s/www/%s"\n'%(root_srv_dom, domain_rss) + \
'\n# Domain user\'s settings\n' + \
'domain_logo = "%s"\n'%domain_logo + \
'domain_rss = "%s"'%domain_rss
tyto.set_file(db.domain_conf, False, set_f)
# Get title domain # Get title domain
#----------------- #-----------------
try: domain_title = db.domain_title try: domain_title = db.domain_title
@ -213,8 +256,7 @@ def create_domain(target):
if '"' in domain_title: if '"' in domain_title:
domain_title = domain_title.replace('"', '') domain_title = domain_title.replace('"', '')
set_f = '# Domain user\'s settings\n' + \ set_f = 'domain_title = "%s"'%domain_title
'domain_title = "%s"'%domain_title
tyto.set_file(db.domain_conf, False, set_f) tyto.set_file(db.domain_conf, False, set_f)
@ -319,27 +361,6 @@ def create_domain(target):
tyto.set_file(db.domain_conf, False, set_f) tyto.set_file(db.domain_conf, False, set_f)
# Get logo's website
#-------------------
try: domain_logo = db.domain_logo
except: domain_logo = 'logo.png'
ask = ''
try:
ask = input(' ├ logo filename ? {%s} '%domain_logo)
except KeyboardInterrupt:
print('')
logs.out("255", '', True)
if ask: domain_logo = ask
set_f = 'domain_logo = "%s"\n'%domain_logo + \
'wip_logo = "%s%s"\n'%(srv_wip_tpl, domain_logo) + \
'www_logo = "%s%s"\n'%(srv_www_tpl, domain_logo)
tyto.set_file(db.domain_conf, False, set_f)
# Get License domain # Get License domain
#------------------- #-------------------
try: domain_license = db.domain_license try: domain_license = db.domain_license
@ -419,7 +440,7 @@ def create_domain(target):
set_f = 'domain_termsurl = "%s"'%domain_termsurl set_f = 'domain_termsurl = "%s"'%domain_termsurl
tyto.set_file(db.domain_conf, False, set_f) tyto.set_file(db.domain_conf, False, set_f)
# CSS Prefix # CSS Prefix
#----------- #-----------
@ -520,6 +541,7 @@ def create_domain(target):
set_f = 'sidebar_items = %d'%int(sidebar_items) set_f = 'sidebar_items = %d'%int(sidebar_items)
tyto.set_file(db.domain_conf, False, set_f) tyto.set_file(db.domain_conf, False, set_f)
# Create domain_footer_about (user custom description in footer) # Create domain_footer_about (user custom description in footer)
#--------------------------------------------------------------- #---------------------------------------------------------------
try: try:
@ -609,7 +631,6 @@ def create_sidebar(option):
# Create new file, or ask if exists with option = 'reset' # Create new file, or ask if exists with option = 'reset'
ask = ' ├ Reset sidebar configuration file ? ' ask = ' ├ Reset sidebar configuration file ? '
log = ' ├ Create source file: %s'%db.sidebar_load
res = '' res = ''
if os.path.exists(db.sidebar_load): if os.path.exists(db.sidebar_load):
try: try:
@ -669,7 +690,7 @@ def create_sidebar(option):
tyto.set_file(db.sidebar_load, 'new', sdb_load) tyto.set_file(db.sidebar_load, 'new', sdb_load)
tyto.create_db_load(db.sidebar_load, db.sidebar_load_db) tyto.create_db_load(db.sidebar_load, db.sidebar_load_db)
print(log) logs.out("33", db.sidebar_load, False)
#=============================# #=============================#
@ -686,7 +707,6 @@ def create_navbar(option):
# Create new file, or ask if exists # Create new file, or ask if exists
ask = ' ├ Reset navbar configuration file ? ' ask = ' ├ Reset navbar configuration file ? '
log = ' ├ Create source file: %s'%db.navbar_load
res = '' res = ''
if os.path.exists(db.navbar_load): if os.path.exists(db.navbar_load):
try: try:
@ -747,7 +767,7 @@ def create_navbar(option):
tyto.set_file(db.navbar_load, 'new', nvb_load) tyto.set_file(db.navbar_load, 'new', nvb_load)
tyto.create_db_load(db.navbar_load, db.navbar_load_db) tyto.create_db_load(db.navbar_load, db.navbar_load_db)
print(log) logs.out("33", db.navbar_load, False)
#========================# #========================#
@ -810,7 +830,6 @@ def create_metas(option):
# Create new default file, or ask if exists # Create new default file, or ask if exists
ask = ' ├ Reset metas configuration file ? ' ask = ' ├ Reset metas configuration file ? '
log = ' ├ Create source file: %s'%db.metas_load
res = '' res = ''
if os.path.exists(db.metas_load): if os.path.exists(db.metas_load):
try: try:
@ -822,7 +841,7 @@ def create_metas(option):
tyto.set_file(db.metas_load, 'new', metas_tags) tyto.set_file(db.metas_load, 'new', metas_tags)
tyto.create_db_load(db.metas_load, db.metas_load_db) tyto.create_db_load(db.metas_load, db.metas_load_db)
print(log) logs.out("33", db.metas_load, False)
#=============================# #=============================#
@ -839,7 +858,6 @@ def create_footer(option):
# Create new default file, or ask if exists # Create new default file, or ask if exists
ask = ' ├ Reset footer configuration file ? ' ask = ' ├ Reset footer configuration file ? '
log = ' ├ Create source file: %s'%db.footer_load
res = '' res = ''
if os.path.exists(db.footer_load): if os.path.exists(db.footer_load):
try: try:
@ -955,6 +973,11 @@ def create_footer(option):
tyto.trans[14][tyto.n] tyto.trans[14][tyto.n]
) + \ ) + \
' </li>\n' + \ ' </li>\n' + \
' <li>\n' + \
' <a href="%s/%s"\n'%(db.domain_www_url, db.domain_rss) + \
' title="RSS 2.0 %s"\n'%db.domain_title + \
' class="footer_item_link">RSS 2.0</a>\n' + \
' </li>\n' + \
' </ul>\n' + \ ' </ul>\n' + \
' </div>\n' + \ ' </div>\n' + \
' <div id="footer_credits">\n' + \ ' <div id="footer_credits">\n' + \
@ -967,7 +990,7 @@ def create_footer(option):
tyto.set_file(db.footer_load, 'new', footer) tyto.set_file(db.footer_load, 'new', footer)
tyto.create_db_load(db.footer_load, db.footer_load_db) tyto.create_db_load(db.footer_load, db.footer_load_db)
print(log) logs.out("33", db.footer_load, False)
# Generic HTML list in footer # Generic HTML list in footer
""" """

View File

@ -43,10 +43,9 @@ def create_metas_page():
all_tags = db.domain_tags + ',' + db.tags all_tags = db.domain_tags + ',' + db.tags
css_file = 'template/style.css' css_file = 'template/style.css'
css_ref = 'media="screen" href="%s%s"'%(db.sub_uri, css_file) css_ref = 'media="screen" href="%s%s"'%(db.sub_uri, css_file)
rss_file = 'rss.xml'
rss_ref = 'type="application/rss+xml" ' + \ rss_ref = 'type="application/rss+xml" ' + \
'href="%s%s" title="RSS 2.0. %s %s %s'%( 'href="%s%s" title="RSS 2.0. %s %s %s'%(
db.sub_uri, rss_file, db.sub_uri, db.domain_rss,
db.domain_title, db.domain_sep, db.domain_short db.domain_title, db.domain_sep, db.domain_short
) )
icon_file = 'favicon.png' icon_file = 'favicon.png'
@ -66,7 +65,7 @@ def create_metas_page():
#----------------------- #-----------------------
global metas global metas
metas = \ metas = \
'<!--# include virtual="/template/metas.html"-->\n' '<!--# include virtual="/template/metas.html"-->\n' + \
' <meta name="viewport" content="%s" />\n'%scale + \ ' <meta name="viewport" content="%s" />\n'%scale + \
' <meta name=”url” content=”%s” />\n'%db.domain_www_url + \ ' <meta name=”url” content=”%s” />\n'%db.domain_www_url + \
' <meta name="language" content="%s" />\n'%db.domain_lang + \ ' <meta name="language" content="%s" />\n'%db.domain_lang + \
@ -466,7 +465,7 @@ def create_navbar(option):
# Close HTML tags # Close HTML tags
menu_html = '\n%s\n%s</ul>\n%s</nav>\n'%(menu_html, 8 * ' ', 6 * ' ') menu_html = '\n%s\n%s</ul>\n%s</nav>\n'%(menu_html, 8 * ' ', 6 * ' ')
tyto.set_file(target, 'New', menu_html) tyto.set_file(target, 'New', menu_html)
print(' ├ Create file: %s'%target) logs.out("33", target, False)
#========================================================# #========================================================#
@ -485,7 +484,6 @@ def create_user_metas(option):
# Create wip metas.html file according to option # Create wip metas.html file according to option
#----------------------------------------------- #-----------------------------------------------
ask_html = ' ├ Replace %s ? '%target ask_html = ' ├ Replace %s ? '%target
log_html = ' ├ Create file: %s'%target
user_metas = '' user_metas = ''
metas_used = ('<meta ', '<link ') metas_used = ('<meta ', '<link ')
res = '' res = ''
@ -507,7 +505,7 @@ def create_user_metas(option):
else: user_metas = ' %s'%line else: user_metas = ' %s'%line
tyto.set_file(target, True, user_metas) tyto.set_file(target, True, user_metas)
print(log_html) logs.out("33", target, False)
#=========================================# #=========================================#
@ -521,7 +519,6 @@ def create_user_footer(option):
elif option == 'pub': target = db.www_footer elif option == 'pub': target = db.www_footer
ask_load = ' ├ Replace HTML footer: %s ? '%target ask_load = ' ├ Replace HTML footer: %s ? '%target
log_load = ' ├ Create file: %s'%target
res = '' res = ''
if not option == 'pub' and os.path.exists(target): if not option == 'pub' and os.path.exists(target):
@ -541,5 +538,5 @@ def create_user_footer(option):
else: user_footer = ' %s'%line else: user_footer = ' %s'%line
tyto.set_file(target, 'New', user_footer) tyto.set_file(target, 'New', user_footer)
print(log_load) logs.out("33", target, False)

View File

@ -58,7 +58,7 @@ def out(nbr, value, out):
'30' : ':? Article %snot yet wip%s: %s'%(CY, CS, value), '30' : ':? Article %snot yet wip%s: %s'%(CY, CS, value),
'31' : ':? Not included. %sMax items reached%s %s'%(CY, CS, value), '31' : ':? Not included. %sMax items reached%s %s'%(CY, CS, value),
'33' : ':D %sCreated file%s: %s'%(CG, CS, value), '33' : ':D %sCreated file%s: %s'%(CG, CS, value),
'34' : ':D Publish %sfile change%s %s'%(CG, CS, value), '34' : ':D %sChanged file%s %s'%(CG, CS, value),
'35' : ':D %sAdd item%s %s'%(CG, CS, value), '35' : ':D %sAdd item%s %s'%(CG, CS, value),
'40' : ':/ %sInactive%s domain "%s"'%(CY, CS, value), '40' : ':/ %sInactive%s domain "%s"'%(CY, CS, value),
'41' : ':? %sIncomplete%s domain "%s"'%(CR, CS, value), '41' : ':? %sIncomplete%s domain "%s"'%(CR, CS, value),

View File

@ -18,7 +18,7 @@
#********************************************************************** #**********************************************************************
import os, sys, shutil, importlib import os, sys, shutil, importlib
import logs, args, db, html, tyto, domain, stats import logs, args, db, html, tyto, domain, stats, rss
#==============================# #==============================#
@ -96,6 +96,9 @@ def publish_article():
# Replace publish HTML line # Replace publish HTML line
replace_line_pub() replace_line_pub()
# Create new ATOM/RSS file
rss.create_feed()
#=================================================# #=================================================#
# Replace line in article containing publish date # # Replace line in article containing publish date #
@ -118,7 +121,7 @@ def replace_line_pub():
else: newfile = '%s\n%s'%(newfile, line) else: newfile = '%s\n%s'%(newfile, line)
tyto.set_file(db.post_www, 'new', newfile) tyto.set_file(db.post_www, 'new', newfile)
logs.out("34", '(date: %s): %s'%(db.date_www, db.post_www), False) logs.out("34", '(HTML date: %s): %s'%(db.date_www, db.post_www), False)
#================================# #================================#

View File

@ -0,0 +1,95 @@
#!/usr/bin/env python3
# Name: Tyto - Littérateur
# Type: ATOM/RSS template
# Description: Create raw RSS template
# file: rss.py
# Folder: /var/lib/tyto/program/
# By echolib (XMPP: im@echolib.re)
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#------------
# funny stats
#------------
# lines:
# functions:
# comments:
#----------------------------------------------------------------------
#*********************************************************************
import os
import logs, db, tyto
#============================#
# Create ATOM/RSS feed #
# only with publish argument #
#----------------------------#
def create_feed():
# Generic fedd Header
set_f = \
'<?xml version="1.0" encoding="utf-8"?>\n' + \
'<rss version="2.0">\n' + \
' <channel>\n' + \
' <title>%s - %s - Flux RSS 2.0</title>\n'%(
db.domain_title, db.domain_www_url
) + \
' <link>%s</link>\n'%db.domain_www_url + \
' <description>%s %s (%s)</description>\n'%(
tyto.trans[19][tyto.n], db.domain_title, db.domain_about
) + \
' <image>\n' + \
' <url>%s/%s</url>\n'%(db.domain_www_url, db.domain_logo) + \
' <title>logo %s</title>\n'%db.domain_title + \
' <link>%s</link>\n'%db.domain_www_url + \
' </image>\n' + \
' <language>%s</language>\n'%db.domain_lang + \
' <category>%s</category>\n'%db.domain_tags + \
' <lastBuildDate>%s</lastBuildDate>\n'%tyto.nowdate() + \
' <copyright>%s</copyright>\n'%db.domain_license + \
' <webMaster>%s</webMaster>\n'%db.domain_mail + \
' <generator>%s/generator>'%tyto.Tyto
rss_item = False
# Loop published articles. Get databases of articles
for post_db in os.listdir(db.articles_db):
if not post_db.endswith('.conf'): continue
# Load DB
post_db = '%s%s'%(db.articles_db, post_db)
exec(open(post_db).read(),globals())
if not hash_www or hash_chk != hash_www: continue
rss_item = True
set_f = \
'%s\n'%set_f + \
'\n <item>\n' + \
' <title>%s</title>\n'%title + \
' <link>%s</link>\n'%http_www + \
' <guid>%s</guid>\n'%http_www + \
' <pubDate>%s</pubDate>\n'%date_www + \
' <description>%s</description>\n'%about + \
' <author>%s</author>\n'%author + \
' <image>\n' + \
' <url>%s</url>\n'%snpic + \
' <title>%s %s</title>\n'%(tyto.trans[20][tyto.n], title) + \
' <link>%s</link>\n'%http_www + \
' </image>\n' + \
' <category>%s</category>\n'%tags + \
' </item>'
# Do nothing if no item
if not rss_item:
logs.out("28", '(ATOM/RSS)', False)
return
set_f = \
'%s\n'%set_f + \
' </chanel>\n' + \
'</rss>'
tyto.set_file(db.www_rss, 'New', set_f)
logs.out("33", db.www_rss, False)
print('')
print(set_f)

View File

@ -61,7 +61,7 @@ def loop_articles(process):
global sti_articles global sti_articles
sti_articles = 0 sti_articles = 0
# Get databases of wip's articles # Get databases of articles
for post_db in os.listdir(db.articles_db): for post_db in os.listdir(db.articles_db):
if not post_db.endswith('.conf'): continue if not post_db.endswith('.conf'): continue

View File

@ -60,7 +60,9 @@ trans = [
('C.G.U.', 'T.O.U'), # 15 ('C.G.U.', 'T.O.U'), # 15
('Mentions légales', 'Legal Notice'), # 16 ('Mentions légales', 'Legal Notice'), # 16
('Conditions Générales d\'Utilisation', 'Terms of Use'), # 17 ('Conditions Générales d\'Utilisation', 'Terms of Use'), # 17
('Loi', 'Law') # 18 ('Loi', 'Law'), # 18
('Articles de', 'Articles from'), # 19
('Lire l\'article:', 'Read the article:') #20
] ]