From 9d8d54d5d428002cdaf7271303f7f5a9972992bc Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Wed, 23 Nov 2022 11:54:27 +0100 Subject: [PATCH] html: progress on HTML page build --- src/var/lib/tyto/program/check.py | 14 +++-- src/var/lib/tyto/program/domain.py | 60 ++++++++++++++------- src/var/lib/tyto/program/html.py | 84 +++++++++++++++++++++++++++++- 3 files changed, 134 insertions(+), 24 deletions(-) diff --git a/src/var/lib/tyto/program/check.py b/src/var/lib/tyto/program/check.py index 07f6101..5f50d8b 100644 --- a/src/var/lib/tyto/program/check.py +++ b/src/var/lib/tyto/program/check.py @@ -55,9 +55,6 @@ def post_IDs(file_post): print(':< Unused argument file') sys.exit(1) - # Set HTML file from file_post - file_html = file_post.replace('.tyto','.html') - # Check if file exists or exit global post_uri post_uri = '%s%s'%(domain.domain_articles, file_post) @@ -65,6 +62,16 @@ def post_IDs(file_post): print(':< Unused file: %s'%post_uri) sys.exit(1) + + global post_url + # Set HTML file from file_post + file_html = file_post.replace('.tyto','.html') + if file_html.endswith('index.html'): + file_html = file_html.remplace('index.html', '') + post_url = '%s%s/%s'%( + domain.domain_protocol, domain.domain_name, file_html + ) + # From argument file_post # Set WEB link prefix. Count / in uri global weburi @@ -1172,6 +1179,7 @@ def create_DB(post_db): 'post_ID = "%s"'%curr_post_ID, 'post_db = "%s"'%post_db, 'post_tmp = "%s"'%post_tmp, + 'post_url = "%s"'%post_url, '\n# Article Status', 'post_chk = ("%s","%s")'%(hash_chk,time_chk), 'post_wip = ("%s","%s")'%(hash_wip,time_wip), diff --git a/src/var/lib/tyto/program/domain.py b/src/var/lib/tyto/program/domain.py index 6a0ecf2..48256ba 100644 --- a/src/var/lib/tyto/program/domain.py +++ b/src/var/lib/tyto/program/domain.py @@ -78,9 +78,10 @@ except: #===========================# # Append new line to a file # #---------------------------# -def append_f(f,line_val): +def append_f(f, line_val): file = open(f, "a") file.write('%s\n'%line_val) + file.close() #======================================# # Just a generic exit # @@ -107,18 +108,12 @@ def exiting(process,out,msg): #==========================#------------------------------------------- def manage_domain(Domain, Opt): if not Opt: - try: - # No option: get domain and print it - print('\n',datas_domain) - except: - sys.exit(0) + try: print('\n',datas_domain) # No option: get domain and print it + except: sys.exit(0) elif Opt == 'New': - try: - # Domain NAME is defined in CLI - set_domain = Domain - except: - set_domain = '' + try: set_domain = Domain # Domain NAME is defined in CLI + except: set_domain = '' add_domain(set_domain) @@ -133,9 +128,9 @@ def manage_domain(Domain, Opt): # Compare before and after domain conf file new_conf_ID = check.get_filesum(domain_conf,True) if not old_conf_ID == new_conf_ID: - exiting('root',2,':D Updated domain configuration file.') + exiting('root', 2, ':D Updated domain configuration file.') else: - exiting('root',2,':D Unchanged domain configuration file.') + exiting('root', 2, ':D Unchanged domain configuration file.') else: sys.exit(0) @@ -147,8 +142,7 @@ def manage_domain(Domain, Opt): #-----------------------------------#---------------------------------- def add_domain(set_domain): # Exit if a domain already exists - if domain_active: - sys.exit(0) + if domain_active: sys.exit(0) global temp_domain temp_domain = '%s/tyto_domain.tmp'%curr_dir @@ -189,6 +183,7 @@ def add_domain(set_domain): post_temp = file.read() for line in post_temp.split('\n'): print(' │ %s'%line) + file.close() # Ask to confirm to write activation domain print(' ├─────────────────────────────') @@ -196,7 +191,25 @@ def add_domain(set_domain): if confirm in ['y', 'Y']: create_domain() else: - exiting('form',1,'') + exiting('form', 1, '') + +#==============# +# Get protocol # +#--------------# +def get_protocol(set_domain): + global domain_protocol + domain_protocol = '' + + # check protocol https, http + if set_domain.startswith('https://'): domain_protocol = 'https://' + elif set_domain.startswith('http://') : domain_protocol = 'http://' + + if domain_protocol: + set_domain = set_domain.replace(domain_protocol,"") + else: + confirm = input(' ├ Use "https" ? ') + if confirm in ['y', 'Y']: domain_protocol = 'https://' + else : domain_protocol = 'http://' #==============================# # If domain name is set in CLI # @@ -204,6 +217,9 @@ def add_domain(set_domain): #------------------------------# def domain_input_confirn(set_domain): global domain_name + + get_protocol(set_domain) + confirm = input(' ├ Add Domain (%s) here ? '%set_domain) if confirm in ['y', 'Y']: # Check if domain already registred @@ -211,20 +227,25 @@ def domain_input_confirn(set_domain): if isdomain in domains_db: dom_folder = globals().get(isdomain,False) if dom_folder and not dom_folder == curr_dir: - exiting('root',2,'\n:/ Domain exists in %s'%dom_folder) + exiting('root', 2, '\n:/ Domain exists in %s'%dom_folder) domain_name = set_domain else: - exiting('root',1,'') + exiting('root', 1, '') #=====================# # Add new domain_name # #---------------------# def domain_input(): - global domain_name + global domain_name, domain_protocol set_domain = input(' ├ Enter Domain Name: ') + if not set_domain: exiting('root', 1, '') else : domain_name = set_domain + domain_protocol = '' + get_protocol(set_domain) + + #====================# # Domain FORM # # domain_name is set # @@ -241,6 +262,7 @@ def domain_form(): # Add settings from domain name before starting form append_f(temp_domain,'domain_name = "%s"'%domain_name) + append_f(temp_domain,'domain_protocol = "%s"'%domain_protocol) append_f(temp_domain,'domain_conf = "%s"'%conf_domain) append_f(temp_domain,'domain_db = "%s"'%domain_db) append_f(temp_domain,'domain_logs = "%s"'%domain_logs) diff --git a/src/var/lib/tyto/program/html.py b/src/var/lib/tyto/program/html.py index 1db253a..cd73b9d 100644 --- a/src/var/lib/tyto/program/html.py +++ b/src/var/lib/tyto/program/html.py @@ -23,10 +23,25 @@ def html_main_page(): post_db = exec(open(check.curr_post_db).read(),globals()) # Metas in HTML page + #------------------- scale = 'width=device-width, initial-scale=1.0' visit = '3 days' title = '%s %s %s'%(post_title, domain.sep_titles, domain.domain_title) tags = '%s,%s'%(domain.domain_tags, post_tags) + icon = '/template/favicon.png' + f_css = '/template/styles.css' + f_rss = '/rss.xml' + i_rss = 'RSS 2.0, %s %s %s'%( + domain.domain_title, domain.sep_titles, domain.domain_name + ) + + # External URL in metas (if exists) + if domain.domain_exturl: + relme = '\n'%( + domain.domain_exturl + ) + else: + relme = '' metas = '\n' + \ '\n'%scale + \ @@ -42,7 +57,72 @@ def html_main_page(): '\n'%post_about + \ '\n'%tags + \ '\n'%post_date + \ - '%s\n'%title + '\n'%post_url + \ + '\n'%(f_rss, i_rss) + \ + '\n'%f_css + \ + '\n'%icon + \ + '%s'%relme + \ + '%s'%title - print(metas) + # header in HTML page + #-------------------- + headers = '
\n'%domain.domain_css + \ + ' \n' + \ + '
\n' + \ + '

\n' + \ + ' %s\n'%( + domain.domain_title, + domain.sep_titles, + domain.domain_name, + domain.domain_title + ) + \ + '

\n' + \ + '

%s

\n'%domain.domain_about + \ + '
\n' + \ + '
\n' + + # Article (in section, including aside) + articles = '
\n' + \ + '
\n'%( + post_ID, domain.domain_css + ) + \ + '
\n' + \ + '

\n' + \ + ' %s\n'%(post_author, post_author) + \ + ' - \n' + \ + ' %s\n'%post_date + \ + '

\n' + \ + '
' + + # Create full page + #----------------- + page = '\n' + \ + ' \n'%domain.domain_lang + \ + ' ' + + # Add tab metas in page + for meta in metas.rsplit('\n'): + page = '%s\n%s%s'%(page, 6*' ', meta) + + page = '%s\n%s\n'%(page, 4*' ') + \ + '%s\n '%(4*' ', post_ID, domain.domain_css) + + # Add tab header in page + for header in headers.rsplit('\n'): + page = '%s\n%s%s'%(page, 6*' ', header) + + # Add tab article in page + for article in articles.rsplit('\n'): + page = '%s\n%s%s'%(page, 6*' ', article) + + print(page)