Fossil SCM

Supply TH1 interpreter with two auxiliary variables: <var>$requested_page</var> (holds the first segment of the requested [/file/src/cgi.c?ln=1199-1209&ci=2022-05-09|PATH_INFO]) and <var>$canonical_page</var> (holds the canonical name of a web-page being served). Also amend default HTML header: add two corresponding classes to the BODY element and move <code><meta charset="UTF-8"></code> to the top.

george 2022-05-09 21:22 trunk
Commit b05a6c6bc826d3c29a4b4a3bde3e20e7337293098c77db135475372ff310b27e
2 files changed +2 -1 +8 -3
+2 -1
--- src/main.c
+++ src/main.c
@@ -138,11 +138,12 @@
138138
139139
struct Global {
140140
int argc; char **argv; /* Command-line arguments to the program */
141141
char *nameOfExe; /* Full path of executable. */
142142
const char *zErrlog; /* Log errors to this file, if not NULL */
143
- const char *zPhase; /* Phase of operation, for use by the error log */
143
+ const char *zPhase; /* Phase of operation, for use by the error log
144
+ ** and for deriving $canonical_page TH1 variable */
144145
int isConst; /* True if the output is unchanging & cacheable */
145146
const char *zVfsName; /* The VFS to use for database connections */
146147
sqlite3 *db; /* The connection to the databases */
147148
sqlite3 *dbConfig; /* Separate connection for global_config table */
148149
char *zAuxSchema; /* Main repository aux-schema */
149150
--- src/main.c
+++ src/main.c
@@ -138,11 +138,12 @@
138
139 struct Global {
140 int argc; char **argv; /* Command-line arguments to the program */
141 char *nameOfExe; /* Full path of executable. */
142 const char *zErrlog; /* Log errors to this file, if not NULL */
143 const char *zPhase; /* Phase of operation, for use by the error log */
 
144 int isConst; /* True if the output is unchanging & cacheable */
145 const char *zVfsName; /* The VFS to use for database connections */
146 sqlite3 *db; /* The connection to the databases */
147 sqlite3 *dbConfig; /* Separate connection for global_config table */
148 char *zAuxSchema; /* Main repository aux-schema */
149
--- src/main.c
+++ src/main.c
@@ -138,11 +138,12 @@
138
139 struct Global {
140 int argc; char **argv; /* Command-line arguments to the program */
141 char *nameOfExe; /* Full path of executable. */
142 const char *zErrlog; /* Log errors to this file, if not NULL */
143 const char *zPhase; /* Phase of operation, for use by the error log
144 ** and for deriving $canonical_page TH1 variable */
145 int isConst; /* True if the output is unchanging & cacheable */
146 const char *zVfsName; /* The VFS to use for database connections */
147 sqlite3 *db; /* The connection to the databases */
148 sqlite3 *dbConfig; /* Separate connection for global_config table */
149 char *zAuxSchema; /* Main repository aux-schema */
150
+8 -3
--- src/style.c
+++ src/style.c
@@ -647,20 +647,20 @@
647647
** prepended.
648648
*/
649649
static const char zDfltHeader[] =
650650
@ <html>
651651
@ <head>
652
-@ <base href="$baseurl/$current_page" />
653652
@ <meta charset="UTF-8">
653
+@ <base href="$baseurl/$current_page" />
654654
@ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
655655
@ <meta name="viewport" content="width=device-width, initial-scale=1.0">
656656
@ <title>$<project_name>: $<title></title>
657657
@ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
658658
@ href="$home/timeline.rss" />
659659
@ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
660660
@ </head>
661
-@ <body class="$current_feature">
661
+@ <body class="$current_feature rpage-$requested_page cpage-$canonical_page">
662662
;
663663
664664
/*
665665
** Returns the default page header.
666666
*/
@@ -749,11 +749,11 @@
749749
/*
750750
** Initialize all the default TH1 variables
751751
*/
752752
static void style_init_th1_vars(const char *zTitle){
753753
const char *zNonce = style_nonce();
754
- char *zDfltCsp;
754
+ char *zDfltCsp, *zSlash = 0;
755755
756756
zDfltCsp = style_csp(1);
757757
/*
758758
** Do not overwrite the TH1 variable "default_csp" if it exists, as this
759759
** allows it to be properly overridden via the TH1 setup script (i.e. it
@@ -769,10 +769,15 @@
769769
Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
770770
Th_Store("home", g.zTop);
771771
Th_Store("index_page", db_get("index-page","/home"));
772772
if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
773773
Th_Store("current_page", local_zCurrentPage);
774
+ /* store the first segment of a path; make a temporary cut if necessary */
775
+ if(( zSlash = strchr(g.zPath,'/') )) *zSlash = 0;
776
+ Th_Store("requested_page", escape_quotes(g.zPath));
777
+ if( zSlash ) *zSlash = '/';
778
+ Th_Store("canonical_page", escape_quotes(g.zPhase+1));
774779
Th_Store("csrf_token", g.zCsrfToken);
775780
Th_Store("release_version", RELEASE_VERSION);
776781
Th_Store("manifest_version", MANIFEST_VERSION);
777782
Th_Store("manifest_date", MANIFEST_DATE);
778783
Th_Store("compiler_name", COMPILER_NAME);
779784
--- src/style.c
+++ src/style.c
@@ -647,20 +647,20 @@
647 ** prepended.
648 */
649 static const char zDfltHeader[] =
650 @ <html>
651 @ <head>
652 @ <base href="$baseurl/$current_page" />
653 @ <meta charset="UTF-8">
 
654 @ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
655 @ <meta name="viewport" content="width=device-width, initial-scale=1.0">
656 @ <title>$<project_name>: $<title></title>
657 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
658 @ href="$home/timeline.rss" />
659 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
660 @ </head>
661 @ <body class="$current_feature">
662 ;
663
664 /*
665 ** Returns the default page header.
666 */
@@ -749,11 +749,11 @@
749 /*
750 ** Initialize all the default TH1 variables
751 */
752 static void style_init_th1_vars(const char *zTitle){
753 const char *zNonce = style_nonce();
754 char *zDfltCsp;
755
756 zDfltCsp = style_csp(1);
757 /*
758 ** Do not overwrite the TH1 variable "default_csp" if it exists, as this
759 ** allows it to be properly overridden via the TH1 setup script (i.e. it
@@ -769,10 +769,15 @@
769 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
770 Th_Store("home", g.zTop);
771 Th_Store("index_page", db_get("index-page","/home"));
772 if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
773 Th_Store("current_page", local_zCurrentPage);
 
 
 
 
 
774 Th_Store("csrf_token", g.zCsrfToken);
775 Th_Store("release_version", RELEASE_VERSION);
776 Th_Store("manifest_version", MANIFEST_VERSION);
777 Th_Store("manifest_date", MANIFEST_DATE);
778 Th_Store("compiler_name", COMPILER_NAME);
779
--- src/style.c
+++ src/style.c
@@ -647,20 +647,20 @@
647 ** prepended.
648 */
649 static const char zDfltHeader[] =
650 @ <html>
651 @ <head>
 
652 @ <meta charset="UTF-8">
653 @ <base href="$baseurl/$current_page" />
654 @ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
655 @ <meta name="viewport" content="width=device-width, initial-scale=1.0">
656 @ <title>$<project_name>: $<title></title>
657 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
658 @ href="$home/timeline.rss" />
659 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
660 @ </head>
661 @ <body class="$current_feature rpage-$requested_page cpage-$canonical_page">
662 ;
663
664 /*
665 ** Returns the default page header.
666 */
@@ -749,11 +749,11 @@
749 /*
750 ** Initialize all the default TH1 variables
751 */
752 static void style_init_th1_vars(const char *zTitle){
753 const char *zNonce = style_nonce();
754 char *zDfltCsp, *zSlash = 0;
755
756 zDfltCsp = style_csp(1);
757 /*
758 ** Do not overwrite the TH1 variable "default_csp" if it exists, as this
759 ** allows it to be properly overridden via the TH1 setup script (i.e. it
@@ -769,10 +769,15 @@
769 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
770 Th_Store("home", g.zTop);
771 Th_Store("index_page", db_get("index-page","/home"));
772 if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
773 Th_Store("current_page", local_zCurrentPage);
774 /* store the first segment of a path; make a temporary cut if necessary */
775 if(( zSlash = strchr(g.zPath,'/') )) *zSlash = 0;
776 Th_Store("requested_page", escape_quotes(g.zPath));
777 if( zSlash ) *zSlash = '/';
778 Th_Store("canonical_page", escape_quotes(g.zPhase+1));
779 Th_Store("csrf_token", g.zCsrfToken);
780 Th_Store("release_version", RELEASE_VERSION);
781 Th_Store("manifest_version", MANIFEST_VERSION);
782 Th_Store("manifest_date", MANIFEST_DATE);
783 Th_Store("compiler_name", COMPILER_NAME);
784

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button