This commit is contained in:
Cyrille L 2023-04-24 23:42:29 +02:00
parent 4825c25f63
commit 26a39155a0
10 changed files with 296 additions and 230 deletions

View File

@ -8,11 +8,12 @@ Tyto - Littérateur
## {0.10.3] ## {0.10.3]
- pre 1.0 - pre 1.0
- Lots of fixes
## [0.10.2] ## [0.10.2]
- Citer dans un texte > `[_` + `_]` - Cite in a text > `[_` + `_]`
- Italique `<em>` > `;_` + `_;` - Italic `<em>` > `;_` + `_;`
- Italique `<i>` > {_:_` + `_:` - Italic `<i>` > {_:_` + `_:`
## [0.10.1] ## [0.10.1]
- Fix with try in check for static page - Fix with try in check for static page

View File

@ -38,7 +38,7 @@
import time, importlib, sys, os, re, datetime import time, importlib, sys, os, re, datetime
from datetime import datetime from datetime import datetime
from time import gmtime, strftime from time import gmtime, strftime
import args, dom, logs, status, db, form, tyto, langs, wip import args, dom, logs, status, db, form, tyto, langs, wip, html
domain_dir = post_err = multi_chk = False domain_dir = post_err = multi_chk = False
@ -237,6 +237,7 @@ def check_process(target):
tyto.protect_icodes(post_bottom) tyto.protect_icodes(post_bottom)
post_bottom = tyto.protect_article post_bottom = tyto.protect_article
# Check header tags configurations # Check header tags configurations
check_needed_tags(post_header.rsplit('\n')) check_needed_tags(post_header.rsplit('\n'))
if post_err: if post_err:
@ -245,15 +246,22 @@ def check_process(target):
return return
print('\n ├ [%s] > %s'%(title, db.uri_file)) print('\n ├ [%s] > %s'%(title, db.uri_file))
# Check optional tags configuration
check_opt_tags(post_header.rsplit('\n')) check_opt_tags(post_header.rsplit('\n'))
if post_err: if post_err:
if db.exists and tyto.exists(db.config): if db.exists and tyto.exists(db.config):
os.remove(db.config) os.remove(db.config)
return return
check_titles() # #1-5 (titles)
# Check for valid contents check_words_tags() # Strongs, italics...
check_content(post_bottom) check_blocks_tags() # Paragraphs, quotes...
check_anchors() # Anchors
check_contents_list() # Lists ul/ol contents
check_legacy_HTML() # Real HTML tags
check_tags_set() # Check _TAG:Name (_image:Name)
check_contents_writer() # Convinience
# Remove db (if exists) on post error and return # Remove db (if exists) on post error and return
if post_err: if post_err:
@ -392,14 +400,14 @@ def if_icodes_bcodes_quotes(post_bottom):
fcodes += 1 fcodes += 1
# icodes # icodes
elif tyto.words_tags[9][0] or tyto.words_tags[9][1] in line: elif tyto.words_tags[8][0] or tyto.words_tags[8][1] in line:
icode_m1 = icode_m2 = 0 icode_m1 = icode_m2 = 0
icode_m1 = line.count(tyto.words_tags[9][0]) icode_m1 = line.count(tyto.words_tags[8][0])
icode_m2 = line.count(tyto.words_tags[9][1]) icode_m2 = line.count(tyto.words_tags[8][1])
if icode_m1 != icode_m2: if icode_m1 != icode_m2:
logs.out("8", 'L=%s. icode "%s" + "%s" > %s'%( logs.out("8", 'L=%s. icode "%s" + "%s" > %s'%(
ln + 1 + ln_header, ln + 1 + ln_header,
tyto.words_tags[9][0], tyto.words_tags[9][1], tyto.words_tags[8][0], tyto.words_tags[8][1],
db.uri_file db.uri_file
), False ), False
) )
@ -736,6 +744,22 @@ def check_snpic(name):
def check_anchors(): def check_anchors():
global post_err global post_err
c_opened = c_closed = 0
c_opened = post_bottom.count(tyto.anchor_tags[0])
c_closed = post_bottom.count(tyto.anchor_tags[1])
if c_opened != c_closed:
logs.out("8", '%s "%s" + "%s" > %s'%(
tyto.anchor_tags[4],
tyto.anchor_tags[0], tyto.anchor_tags[1],
db.uri_file
), False)
post_err = True
else:
globals()['post_%s'%tyto.anchor_tags[4]] = int(c_opened)
# Anchor target # Anchor target
if nbr_ancs > 0: if nbr_ancs > 0:
# Create anchors names targets # Create anchors names targets
@ -766,11 +790,11 @@ def check_anchors():
post_err = True post_err = True
return return
# Check in anchor link has target one # Check if anchor link has target one
else: else:
for ln, line in enumerate(post_bottom.rsplit('\n'), 1): for ln, line in enumerate(post_bottom.rsplit('\n'), 1):
# Anchor link # Anchor link
if tyto.words_tags[0][0] and tyto.words_tags[0][1] in line: if tyto.anchor_tags[0] and tyto.anchor_tags[1] in line:
anchors = re.findall(r">_(.*?)_<", line) anchors = re.findall(r">_(.*?)_<", line)
for anchor in anchors: for anchor in anchors:
anchor_name = anchor.rsplit(':')[0].lstrip() anchor_name = anchor.rsplit(':')[0].lstrip()
@ -801,19 +825,13 @@ def check_titles():
post_titles += 1 post_titles += 1
#============================================#
# Check tags for words (strongs, italics...) #
# Set stats for each one #
#--------------------------------------------#
def check_words_tags():
global post_err, post_bottom
#===========================#
# Check tags in post_bottom #
#---------------------------#
def check_content(post_bottom):
global post_err
check_titles()
# Check tags for words (strongs, italics...)
# Set stats for each one
#-------------------------------------------
for tag in tyto.words_tags: for tag in tyto.words_tags:
c_opened = c_closed = 0 c_opened = c_closed = 0
@ -833,9 +851,13 @@ def check_content(post_bottom):
globals()['post_%s'%tag[4]] = int(c_opened) globals()['post_%s'%tag[4]] = int(c_opened)
# Check block tags paragraphs, qyotes...) #=========================================#
# Set stats for each one # Check block tags paragraphs, quotes...) #
#------------------------------------------- # Set stats for each one #
#-----------------------------------------#-
def check_blocks_tags():
global post_err
for tag in tyto.block_tags: for tag in tyto.block_tags:
c_opened = c_closed = 0 c_opened = c_closed = 0
@ -853,14 +875,12 @@ def check_content(post_bottom):
globals()['post_%s'%tag[4]] = int(c_opened) globals()['post_%s'%tag[4]] = int(c_opened)
# Check if anchor has target #====================================#
# Count anchors target # Lists: check if contents are valid #
#--------------------------- #------------------------------------#
check_anchors() def check_contents_list():
global post_err
# Lists: check if contents are valid
#-----------------------------------
if post_lists > 0: if post_lists > 0:
inlist = False inlist = False
for ln, line in enumerate(post_bottom.rsplit('\n'), 1): for ln, line in enumerate(post_bottom.rsplit('\n'), 1):
@ -882,9 +902,31 @@ def check_content(post_bottom):
), False) ), False)
post_err = True post_err = True
#==================================#
# Legacy HTML Tags, check if aired #
#----------------------------------#
def check_legacy_HTML():
global post_err
for tag in tyto.leg_html_tags:
leg1 = post_bottom.count(tag[0])
leg2 = post_bottom.count(tag[1])
if leg1 != leg2:
logs.out("8", '"%s" + "%s" > %s'%(
tag[0], tag[1], db.uri_file
), False)
post_err = True
#================================#
# Check for all match _TAGS:NAME #
# (from content in header) #
# _image:, _raw:... #
#--------------------------------#
def check_tags_set():
global post_err
# Check for all match _TAGS:NAME from content in header
#------------------------------------------------------
set_tags = () set_tags = ()
for ln, line in enumerate(post_bottom): for ln, line in enumerate(post_bottom):
for htag in tyto.head_tags: for htag in tyto.head_tags:
@ -905,20 +947,10 @@ def check_content(post_bottom):
post_err = True post_err = True
# Legacy HTML not paired error #================================================#
for tag in tyto.leg_html_tags: # Template Tags (warning for not paired symbols) #
leg1 = post_bottom.count(tag[0]) #------------------------------------------------#
leg2 = post_bottom.count(tag[1]) def check_contents_writer():
if leg1 != leg2:
logs.out("8", '"%s" + "%s" > %s'%(
tag[0], tag[1], db.uri_file
), False)
post_err = True
# Template Tags (warning for not paired symbols)
#-----------------------------------------------
for tag in tyto.tpl_tags: for tag in tyto.tpl_tags:
tpl1 = post_bottom.count(tag[0]) tpl1 = post_bottom.count(tag[0])
tpl2 = post_bottom.count(tag[1]) tpl2 = post_bottom.count(tag[1])
@ -946,7 +978,7 @@ def check_static_posts():
try: try:
post_datas = open(srv_post, "r").read() post_datas = open(srv_post, "r").read()
if not re.findall( if not re.findall(
tyto.tags_html_mods[dom.wip_metas_f], html.tags_html_mods[dom.wip_metas_f],
post_datas post_datas
): ):
globals()[static] = "True" globals()[static] = "True"

View File

@ -213,96 +213,96 @@ if not hole:
if active: if active:
ready = True ready = True
wip_html_mods = \ wip_html_mods = \
( (
eval(str('wip_navbar_f')), eval(str('wip_navbar_f')),
eval(str('wip_sidebar_f')), eval(str('wip_sidebar_f')),
eval(str('wip_metas_f')), eval(str('wip_metas_f')),
eval(str('wip_footer_f')) eval(str('wip_footer_f'))
) )
www_html_mods = \ www_html_mods = \
( (
eval(str('www_navbar_f')), eval(str('www_navbar_f')),
eval(str('www_sidebar_f')), eval(str('www_sidebar_f')),
eval(str('www_metas_f')), eval(str('www_metas_f')),
eval(str('www_footer_f')) eval(str('www_footer_f'))
) )
metas = \ metas = \
( (
eval(str('metas_f')), eval(str('metas_f')),
eval(str('wip_metas_f')), eval(str('wip_metas_f')),
eval(str('www_metas_f')) eval(str('www_metas_f'))
) )
navbars = \ navbars = \
( (
eval(str('navbar_f')), eval(str('navbar_f')),
eval(str('wip_navbar_f')), eval(str('wip_navbar_f')),
eval(str('www_navbar_f')) eval(str('www_navbar_f'))
) )
sidebars = \ sidebars = \
( (
eval(str('sidebar_f')), eval(str('sidebar_f')),
eval(str('wip_sidebar_f')), eval(str('wip_sidebar_f')),
eval(str('www_sidebar_f')) eval(str('www_sidebar_f'))
) )
footers = \ footers = \
( (
eval(str('footer_f')), eval(str('footer_f')),
eval(str('wip_footer_f')), eval(str('wip_footer_f')),
eval(str('www_footer_f')), eval(str('www_footer_f')),
eval(str('footer_about_f')) eval(str('footer_about_f'))
) )
templates = \ templates = \
( (
eval(str('wip_logo_f')), eval(str('wip_logo_f')),
eval(str('wip_css_f')), eval(str('wip_css_f')),
eval(str('wip_navbar_f')), eval(str('wip_navbar_f')),
eval(str('wip_sidebar_f')), eval(str('wip_sidebar_f')),
eval(str('wip_metas_f')), eval(str('wip_metas_f')),
eval(str('wip_footer_f')), eval(str('wip_footer_f')),
eval(str('wip_stats_f')), eval(str('wip_stats_f')),
eval(str('www_logo_f')), eval(str('www_logo_f')),
eval(str('www_css_f')), eval(str('www_css_f')),
eval(str('www_navbar_f')), eval(str('www_navbar_f')),
eval(str('www_sidebar_f')), eval(str('www_sidebar_f')),
eval(str('www_metas_f')), eval(str('www_metas_f')),
eval(str('www_footer_f')), eval(str('www_footer_f')),
eval(str('www_stats_f')), eval(str('www_stats_f')),
eval(str('www_rss_f')), eval(str('www_rss_f')),
) )
modules = \ modules = \
{ {
"metas" : metas, "metas" : metas,
"navbar" : navbars, "navbar" : navbars,
"sidebar" : sidebars, "sidebar" : sidebars,
"footer" : footers, "footer" : footers,
"template": templates, "template": templates,
} }
templates_files_wip = \ templates_files_wip = \
( (
eval(str('wip_logo_f')), eval(str('wip_logo_f')),
eval(str('wip_css_f')), eval(str('wip_css_f')),
eval(str('wip_navbar_f')), eval(str('wip_navbar_f')),
eval(str('wip_sidebar_f')), eval(str('wip_sidebar_f')),
eval(str('wip_metas_f')), eval(str('wip_metas_f')),
eval(str('wip_footer_f')), eval(str('wip_footer_f')),
eval(str('wip_stats_f')), eval(str('wip_stats_f')),
) )
templates_files_www = \ templates_files_www = \
( (
eval(str('www_logo_f')), eval(str('www_logo_f')),
eval(str('www_css_f')), eval(str('www_css_f')),
eval(str('www_navbar_f')), eval(str('www_navbar_f')),
eval(str('www_sidebar_f')), eval(str('www_sidebar_f')),
eval(str('www_metas_f')), eval(str('www_metas_f')),
eval(str('www_footer_f')), eval(str('www_footer_f')),
eval(str('www_stats_f')), eval(str('www_stats_f')),
eval(str('www_rss_f')) eval(str('www_rss_f'))
) )
#====================================# #====================================#
# Check if domain is ready and ready # # Check if domain is ready and ready #

View File

@ -256,7 +256,7 @@ def create_domain(target):
srv_www_tpl = "%s/www/template/"%root_srv_dom srv_www_tpl = "%s/www/template/"%root_srv_dom
set_f = \ set_f = \
'# Servers directories\n' + \ '\n# Servers directories\n' + \
'srv_root = "%s/"\n'%srv + \ 'srv_root = "%s/"\n'%srv + \
'srv_domain = "%s/"\n'%root_srv_dom + \ 'srv_domain = "%s/"\n'%root_srv_dom + \
'srv_wip = "%s/wip/"\n'%root_srv_dom + \ 'srv_wip = "%s/wip/"\n'%root_srv_dom + \
@ -284,7 +284,7 @@ def create_domain(target):
'www_sidebar_f = "%ssidebar.html"\n'%srv_www_tpl + \ 'www_sidebar_f = "%ssidebar.html"\n'%srv_www_tpl + \
'www_metas_f = "%smetas.html"\n'%srv_www_tpl + \ 'www_metas_f = "%smetas.html"\n'%srv_www_tpl + \
'www_footer_f = "%sfooter.html"\n'%srv_www_tpl + \ 'www_footer_f = "%sfooter.html"\n'%srv_www_tpl + \
'www_stats_f = "%s"'%stats_www_f 'www_stats_f = "%s"\n'%stats_www_f
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -304,7 +304,7 @@ def create_domain(target):
'\n# Domain user\'s settings\n' + \ '\n# Domain user\'s settings\n' + \
'logo = "%s"\n'%logo + \ 'logo = "%s"\n'%logo + \
'styles = "styles.css"\n' + \ 'styles = "styles.css"\n' + \
'rss = "%s"'%rss 'rss = "%s"\n'%rss
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -322,7 +322,7 @@ def create_domain(target):
if not str(rss_items).isdigit() or not int(rss_items) > 1: if not str(rss_items).isdigit() or not int(rss_items) > 1:
rss_items = 100 rss_items = 100
set_f = 'rss_items = %d'%int(rss_items) set_f = 'rss_items = %d\n'%int(rss_items)
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -339,7 +339,7 @@ def create_domain(target):
if not title: invalid = True if not title: invalid = True
else: title = tyto.convert_altname(title) else: title = tyto.convert_altname(title)
set_f = 'title = "%s"'%title set_f = 'title = "%s"\n'%title
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -354,7 +354,7 @@ def create_domain(target):
if answer: date = answer if answer: date = answer
set_f = 'date = "%s"'%date set_f = 'date = "%s"\n'%date
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -371,7 +371,7 @@ def create_domain(target):
if not about: invalid = True if not about: invalid = True
else: about = tyto.convert_altname(about) else: about = tyto.convert_altname(about)
set_f = 'about = "%s"'%about set_f = 'about = "%s"\n'%about
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -391,7 +391,7 @@ def create_domain(target):
if not tyto.exists('%s/site_%s.py'%(trans_dir, lang_site)): if not tyto.exists('%s/site_%s.py'%(trans_dir, lang_site)):
lang_site = 'en' lang_site = 'en'
set_f = 'lang_site = "%s"'%lang_site set_f = 'lang_site = "%s"\n'%lang_site
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -405,11 +405,12 @@ def create_domain(target):
), False) ), False)
if answer: mail = answer if answer: mail = answer
if not re.search('^\w+@\w+.\w+$', mail): passplus = mail.replace('+', '').replace('-', '')
if not re.search('^\w+@\w+.\w+$', passplus):
logs.out("3", mail, False) logs.out("3", mail, False)
invalid = True invalid = True
set_f = 'mail = "%s"'%mail set_f = 'mail = "%s"\n'%mail
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -426,7 +427,7 @@ def create_domain(target):
if not tags: invalid = True if not tags: invalid = True
elif '"' in tags: tags = tags.replace('"', '') elif '"' in tags: tags = tags.replace('"', '')
set_f = 'tags = "%s"'%tags set_f = 'tags = "%s"\n'%tags
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -442,7 +443,7 @@ def create_domain(target):
if answer: domlicense = answer if answer: domlicense = answer
if '"' in domlicense: domlicense = domlicense.replace('"', '') if '"' in domlicense: domlicense = domlicense.replace('"', '')
set_f = 'license = "%s"'%domlicense set_f = 'license = "%s"\n'%domlicense
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -462,7 +463,7 @@ def create_domain(target):
logs.out("2", '"http(s)://%s"%s'%(licurl, langs.site.q), False) logs.out("2", '"http(s)://%s"%s'%(licurl, langs.site.q), False)
licurl = '' licurl = ''
set_f = 'license_url = "%s"'%licurl set_f = 'license_url = "%s"\n'%licurl
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -482,7 +483,7 @@ def create_domain(target):
logs.out("2", '"http(s)://%s"%s'%(legalurl, langs.site.q), False) logs.out("2", '"http(s)://%s"%s'%(legalurl, langs.site.q), False)
legalurl = '' legalurl = ''
set_f = 'legal_url = "%s"'%legalurl set_f = 'legal_url = "%s"\n'%legalurl
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -502,7 +503,7 @@ def create_domain(target):
logs.out("2", '"http(s)://%s"%s'%(termsurl, langs.site.q), False) logs.out("2", '"http(s)://%s"%s'%(termsurl, langs.site.q), False)
termsurl = '' termsurl = ''
set_f = 'terms_url = "%s"'%termsurl set_f = 'terms_url = "%s"\n'%termsurl
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -520,7 +521,7 @@ def create_domain(target):
logs.out("3", css, False) logs.out("3", css, False)
css = 'tyto' css = 'tyto'
set_f = 'css = "%s"'%css set_f = 'css = "%s"\n'%css
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -538,27 +539,27 @@ def create_domain(target):
logs.out("3", answer, False) logs.out("3", answer, False)
sep = "-" sep = "-"
set_f = 'sep = "%s"'%sep set_f = 'sep = "%s"\n'%sep
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
# Show article source ? # Show article source ?
#---------------------- #----------------------
try: try:
dom.article_code if dom.article_code: article_code = "True"
article_code = "True" else: article_code = "False"
except: except:
article_code = "False" article_code = "False"
answer = ('%s%s {%s} '%( answer = asking('%s%s {%s} (Y|n) '%(
langs.site.form_pscode, langs.site.q, article_code langs.site.form_pscode, langs.site.q, str(article_code)
), False) ), False)
if answer: if answer:
if answer in answer_yes: article_code = "True" if answer in answer_yes: article_code = "True"
else: article_code = "False" else: article_code = "False"
set_f = 'article_code = %s'%article_code set_f = 'article_code = %s\n'%article_code
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -578,7 +579,7 @@ def create_domain(target):
logs.out("2", '"http(s)://%s"%s'%(relme, langs.site.q), False) logs.out("2", '"http(s)://%s"%s'%(relme, langs.site.q), False)
relmel = '' relmel = ''
set_f = 'relme = "%s"'%relme set_f = 'relme = "%s"\n'%relme
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -599,7 +600,7 @@ def create_domain(target):
else: else:
sdb_title = tyto.convert_altname(sdb_title) sdb_title = tyto.convert_altname(sdb_title)
set_f = 'sidebar_title = "%s"'%sdb_title set_f = 'sidebar_title = "%s"\n'%sdb_title
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -617,7 +618,7 @@ def create_domain(target):
if not str(sdb_items).isdigit() or not int(sdb_items) in range(1,17): if not str(sdb_items).isdigit() or not int(sdb_items) in range(1,17):
sdb_items = 6 sdb_items = 6
set_f = 'sidebar_items = %d'%int(sdb_items) set_f = 'sidebar_items = %d\n'%int(sdb_items)
tyto.set_file(dom.config, False, set_f) tyto.set_file(dom.config, False, set_f)
@ -650,13 +651,17 @@ def create_domain(target):
# Activate Domain # Activate Domain
#---------------- #----------------
tyto.set_file(dom.config, False, '\nactivated = True') tyto.set_file(dom.config, False, '\nactivated = True')
shutil.copy2(dom.config, config_bkp)
logs.out("32", config_bkp, False)
# RELoad config # RELoad config
#-------------- #--------------
importlib.reload(dom) importlib.reload(dom)
# Backup and create local user dir
if not os.makedirs(dom.articles_db_d, exist_ok=True):
logs.out("33", dom.articles_db_d, False)
shutil.copy2(dom.config, config_bkp)
logs.out("32", config_bkp, False)
# Create folders from configuration file # Create folders from configuration file
#--------------------------------------- #---------------------------------------
@ -674,7 +679,7 @@ def create_domain(target):
logs.out("37", folder, False) logs.out("37", folder, False)
else: else:
os.makedirs(folder, exist_ok=True) os.makedirs(folder, exist_ok=True)
logs.out("33", foloder, False) logs.out("33", folder, False)
print('') print('')
@ -682,7 +687,7 @@ def create_domain(target):
# Create in _configs/ modules files # Create in _configs/ modules files
#---------------------------------- #----------------------------------
html.create_user_metass('new') html.create_user_metas('new')
html.create_navbar('new') html.create_navbar('new')
html.create_sidebar('new') html.create_sidebar('new')
html.create_user_footer('new') html.create_user_footer('new')
@ -1043,7 +1048,7 @@ def create_footer(option):
' <li class="footer_item">%s%s \n'%( ' <li class="footer_item">%s%s \n'%(
langs.site.feed, langs.site.pp langs.site.feed, langs.site.pp
) + \ ) + \
' <a href="%s/%s"\n'%(dom.www_url, dom.rss) + \ ' <a href="/%s"\n'%(dom.rss) + \
' title="RSS 2.0 - %s"\n'%dom.title + \ ' title="RSS 2.0 - %s"\n'%dom.title + \
' class="footer_item_link">RSS 2.0</a>\n' + \ ' class="footer_item_link">RSS 2.0</a>\n' + \
' </li>\n' + \ ' </li>\n' + \

View File

@ -42,6 +42,16 @@ pub_opts = ('www', 'pub')
# Not a line if it starts with...(for sidebar, navbar) # Not a line if it starts with...(for sidebar, navbar)
nolines = ('#', '/') nolines = ('#', '/')
# For static modules
if dom.ready:
tags_html_mods = \
{
dom.wip_navbar_f : '<!--# include virtual="/template/navbar.html"-->',
dom.wip_sidebar_f : '<!--# include virtual="/template/sidebar.html"-->',
dom.wip_metas_f : '<!--# include virtual="/template/metas.html"-->',
dom.wip_footer_f : '<!--# include virtual="/template/footer.html"-->'
}
#==========================# #==========================#
# Load article DB # # Load article DB #
# Start HTML page sections # # Start HTML page sections #
@ -85,7 +95,7 @@ def create_metas_page():
#----------------------- #-----------------------
global metas global metas
metas = \ metas = \
tyto.tags_html_mods[dom.wip_metas_f] + '\n' + \ tags_html_mods[dom.wip_metas_f] + '\n' + \
' <meta name="viewport" content="%s">\n'%scale + \ ' <meta name="viewport" content="%s">\n'%scale + \
' <meta name=”url” content=”%s”>\n'%dom.www_url + \ ' <meta name=”url” content=”%s”>\n'%dom.www_url + \
' <meta name="language" content="%s">\n'%dom.lang_site + \ ' <meta name="language" content="%s">\n'%dom.lang_site + \
@ -167,7 +177,7 @@ def create_main_page(target, article_bottom):
' <p id="site_about">%s</p>\n'%dom.about + \ ' <p id="site_about">%s</p>\n'%dom.about + \
' </div>\n' + \ ' </div>\n' + \
' </header>\n' + \ ' </header>\n' + \
tyto.tags_html_mods[dom.wip_navbar_f] + '\n' + \ tags_html_mods[dom.wip_navbar_f] + '\n' + \
' <article id="article_main">\n' + \ ' <article id="article_main">\n' + \
' <h1 accesskey="t" id="post_title"\n' + \ ' <h1 accesskey="t" id="post_title"\n' + \
' title="[%s] %s %s %s %s">%s</h1>\n'%( ' title="[%s] %s %s %s %s">%s</h1>\n'%(
@ -189,8 +199,8 @@ def create_main_page(target, article_bottom):
' </div>\n' + \ ' </div>\n' + \
' </article>\n' + \ ' </article>\n' + \
'\n' + \ '\n' + \
tyto.tags_html_mods[dom.wip_sidebar_f] + '\n' + \ tags_html_mods[dom.wip_sidebar_f] + '\n' + \
tyto.tags_html_mods[dom.wip_footer_f] + '\n' + \ tags_html_mods[dom.wip_footer_f] + '\n' + \
' </body>\n' + \ ' </body>\n' + \
'</html>' '</html>'

View File

@ -37,7 +37,7 @@ import os, sys
import langs import langs
# Use to mark new article # Use to mark new article
shebang = "#!/usr/bin/tyto" shebang = "#!/NEW"
# Set colors # Set colors
CS = '\033[0;0m' CS = '\033[0;0m'

View File

@ -60,21 +60,24 @@ def manage(target):
actions[target](option) actions[target](option)
# article target # article target
#--------------- #---------------
else: else:
filepost = "%s%s.tyto"%(dom.user_dir, args.target) filepost = "%s%s.tyto"%(dom.articles_d, args.target)
if tyto.exists(filepost): if tyto.exists(filepost):
logs.out("81", filepost, True) logs.out("81", filepost, True)
else: else:
form.asking("%s%s %s"%( form.asking("%s%s {%s}%s "%(
langs.site.new_post, langs.site.new_post,
langs.site.q, langs.site.q,
filepost filepost,
langs.site.q
), True) ), True)
post = tyto.new_article%(args.target, post = tyto.new_article%(logs.shebang,
args.target,
dom.user, dom.user,
tyto.nowdate().rsplit(' ')[0] tyto.nowdate().rsplit(' ')[0]
) )

View File

@ -38,7 +38,7 @@ import args, dom, logs, tyto, html, db
def domain(): def domain():
if dom.hole: logs.out("13", '', True) if dom.hole: logs.out("13", '', True)
elif args.action == 'new': return elif args.action == 'new' and args.target == "domain": return
elif args.act_err: logs.out("11", args.action, True) elif args.act_err: logs.out("11", args.action, True)
elif not dom.exists: logs.out("10", '', True) elif not dom.exists: logs.out("10", '', True)
elif dom.corrupt: logs.out("39", dom.shortname, True) elif dom.corrupt: logs.out("39", dom.shortname, True)

View File

@ -104,11 +104,6 @@ headers = \
# [5] = name for stats and log. # [5] = name for stats and log.
#------------------------------------------------------------- #-------------------------------------------------------------
words_tags = [ words_tags = [
(
'>_', '_<',
'<a class="anchor_link" href="#%s">', '</a>',
'anchors'
),
( (
'*_', '_*', '*_', '_*',
'<strong class="strong">', '</strong>', '<strong class="strong">', '</strong>',
@ -165,6 +160,14 @@ block_tags = [
('<<', '>>', '<div class="%s">', '</div>', 'div'), ('<<', '>>', '<div class="%s">', '</div>', 'div'),
] ]
# Anchor tags
anchor_tags = \
(
'>_', '_<',
'<a class="anchor_link" href="#%s">', '</a>',
'anchors'
)
# Tags that do not need to be paired # Tags that do not need to be paired
#----------------------------------- #-----------------------------------
single_tags = [ single_tags = [
@ -235,22 +238,13 @@ quote_tags = [
# Tags to check in header in content _TAG # Tags to check in header in content _TAG
head_tags = ("image:", "raw:", "code;") head_tags = ("image:", "raw:", "code;")
# For static modules
tags_html_mods = \
{
dom.wip_navbar_f : '<!--# include virtual="/template/navbar.html"-->',
dom.wip_sidebar_f : '<!--# include virtual="/template/sidebar.html"-->',
dom.wip_metas_f : '<!--# include virtual="/template/metas.html"-->',
dom.wip_footer_f : '<!--# include virtual="/template/footer.html"-->'
}
# Valid characters for some datas # Valid characters for some datas
chrs_invalid = \ chrs_invalid = \
set('{}[]_()+*=/:%~´') set('{}[]_()+*=/:%~´')
new_article = """%s new_article = """%s
# tyto new %s # Tyto - Litterateur (tyto new %s)
title: title:
about: about:
@ -262,7 +256,9 @@ date: %s
Le générateur de sites web Libre Le générateur de sites web Libre
Tyto - Littérateur Tyto - Littérateur
#image: Image-1 # Use this image for social networks
#snpic: Pic-1
#image: Pic-1
URI URI
Texte-alternatif Texte-alternatif
@ -271,8 +267,12 @@ date: %s
Text-alternatif Text-alternatif
----- -----
#_image:Pic-1 c=title_class
#3 #1
((
))
""" """
@ -448,7 +448,7 @@ def protect_bcodes_quotes(process, post_bottom):
if not in_quote and not in_bcode: if not in_quote and not in_bcode:
if not line: if not line:
continue continue
elif line.startswith('#') and not line.startswith(titles_tags): elif line.startswith('#') and not line.startswith(titles_user):
continue continue
# bcode convertion to base64 # bcode convertion to base64
@ -492,7 +492,7 @@ def protect_icodes(post_bottom):
# Get only lines that contains code # Get only lines that contains code
for ln, line in enumerate(post_bottom.rsplit('\n')): for ln, line in enumerate(post_bottom.rsplit('\n')):
if not words_tags[9][0] in line: continue if not words_tags[8][0] in line: continue
# Iterate (c)haracter in line # Iterate (c)haracter in line
for i, c in enumerate(line): for i, c in enumerate(line):
@ -506,17 +506,17 @@ def protect_icodes(post_bottom):
if c_b == '{' and not c_bb == '\\': if c_b == '{' and not c_bb == '\\':
in_icode = True in_icode = True
nbr_icodes += 1 nbr_icodes += 1
code = words_tags[9][2] code = words_tags[8][2]
continue continue
# No more in code if # No more in code if
if c_a == '}' and not c_b == '\\': if c_a == '}' and not c_b == '\\':
in_icode = False in_icode = False
src_code = convert_altname(src_code) src_code = convert_altname(src_code)
code = '%s%s%s'%(code, src_code, words_tags[9][3]) code = '%s%s%s'%(code, src_code, words_tags[8][3])
b64_code = b64('Encode', code, 'I64.', '.I64') b64_code = b64('Encode', code, 'I64.', '.I64')
rep_code = "%s%s%s"%( rep_code = "%s%s%s"%(
words_tags[9][0], rep_code, words_tags[9][1] words_tags[8][0], rep_code, words_tags[8][1]
) )
protect_article = protect_article.replace(rep_code, b64_code) protect_article = protect_article.replace(rep_code, b64_code)

View File

@ -161,6 +161,7 @@ def wip_article(target):
# Convert contents from modules # Convert contents from modules
wip_clean_lines() # Remove comments and empty lines
wip_images() # Images_%i from headers in DB wip_images() # Images_%i from headers in DB
wip_single_tags() # br /, anchors wip_single_tags() # br /, anchors
wip_words_tags() # Paragraphs, strongs, italics wip_words_tags() # Paragraphs, strongs, italics
@ -223,6 +224,31 @@ def file_to_string(post_file):
else: post_header = '%s\n%s'%(post_header, line) else: post_header = '%s\n%s'%(post_header, line)
#=================================#
# Remove comments and empty lines #
#---------------------------------#
def wip_clean_lines():
global post_bottom
# Remove comments
if db.comments > 0:
for line in post_bottom.rsplit('\n'):
if line.startswith('#') and not line.startswith(tyto.titles_user):
replace_in_post(line, "")
# Remove empty lines
post_temp = ''
for line in post_bottom.rsplit('\n'):
if not line: continue
if not post_temp: post_temp = line
else: post_temp = "%s\n%s"%(post_temp, line)
post_bottom = post_temp
#=========================================# #=========================================#
# Create real static page, by # # Create real static page, by #
# including modules contents in HTML page # # including modules contents in HTML page #
@ -240,7 +266,7 @@ def wip_static():
wip_module = open(module, 'r').read() wip_module = open(module, 'r').read()
wip_html_post = \ wip_html_post = \
wip_html_post.replace( wip_html_post.replace(
tyto.tags_html_mods[module], html.tags_html_mods[module],
wip_module wip_module
) )
tyto.set_file(db.post_wip, "New", wip_html_post) tyto.set_file(db.post_wip, "New", wip_html_post)
@ -282,21 +308,7 @@ def wip_single_tags():
#----------------------------------# #----------------------------------#
def wip_words_tags(): def wip_words_tags():
# Strongs, italics... # Strongs, italics...
# (Stop after 8 tags)
# For anchor (0), must do it differently
m = 0
for tag in tyto.words_tags: for tag in tyto.words_tags:
if m == 0:
m += 1
# Close anchor (generic)
replace_in_post(tag[1],
tag[3]
)
continue
elif m > 8:
break
# Open tag # Open tag
replace_in_post(tag[0], replace_in_post(tag[0],
tag[2] tag[2]
@ -305,7 +317,6 @@ def wip_words_tags():
replace_in_post(tag[1], replace_in_post(tag[1],
tag[3] tag[3]
) )
m += 1
for ln, line in enumerate(post_bottom.rsplit('\n')): for ln, line in enumerate(post_bottom.rsplit('\n')):
@ -339,11 +350,15 @@ def wip_words_tags():
anchor_links = re.findall(r'>_(.+?):', line) anchor_links = re.findall(r'>_(.+?):', line)
for item in anchor_links: for item in anchor_links:
anchor_id = '%s%s:'%(tyto.words_tags[0][0], item) anchor_id = '%s%s:'%(tyto.anchor_tags[0], item)
replace_in_post(anchor_id, replace_in_post(anchor_id,
tyto.words_tags[0][2]%item tyto.anchor_tags[2]%item
) )
replace_in_post(tyto.anchor_tags[1],
tyto.anchor_tags[3]
)
#========================# #========================#
# Convert links set inDB # # Convert links set inDB #
@ -730,10 +745,10 @@ def wip_titles():
global post_bottom global post_bottom
for line in post_bottom.rsplit('\n'): for line in post_bottom.rsplit('\n'):
if line.startswith('#'): if line.startswith(tyto.titles_user):
tx = int(line[1]) tx = line[1]
title_name = line[2: len(line)].lstrip() title_name = line[2: len(line)].lstrip()
title_html = tyto.titles_tags[tx][1]%title_name title_html = tyto.titles_tags[int(tx)][1]%title_name
replace_in_post(line, title_html) replace_in_post(line, title_html)
wip_titles_div() wip_titles_div()