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.
Commit
b05a6c6bc826d3c29a4b4a3bde3e20e7337293098c77db135475372ff310b27e
Parent
b3e534fa88c34de…
2 files changed
+2
-1
+8
-3
+2
-1
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -138,11 +138,12 @@ | ||
| 138 | 138 | |
| 139 | 139 | struct Global { |
| 140 | 140 | int argc; char **argv; /* Command-line arguments to the program */ |
| 141 | 141 | char *nameOfExe; /* Full path of executable. */ |
| 142 | 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 */ | |
| 143 | + const char *zPhase; /* Phase of operation, for use by the error log | |
| 144 | + ** and for deriving $canonical_page TH1 variable */ | |
| 144 | 145 | int isConst; /* True if the output is unchanging & cacheable */ |
| 145 | 146 | const char *zVfsName; /* The VFS to use for database connections */ |
| 146 | 147 | sqlite3 *db; /* The connection to the databases */ |
| 147 | 148 | sqlite3 *dbConfig; /* Separate connection for global_config table */ |
| 148 | 149 | char *zAuxSchema; /* Main repository aux-schema */ |
| 149 | 150 |
| --- 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 @@ | ||
| 647 | 647 | ** prepended. |
| 648 | 648 | */ |
| 649 | 649 | static const char zDfltHeader[] = |
| 650 | 650 | @ <html> |
| 651 | 651 | @ <head> |
| 652 | -@ <base href="$baseurl/$current_page" /> | |
| 653 | 652 | @ <meta charset="UTF-8"> |
| 653 | +@ <base href="$baseurl/$current_page" /> | |
| 654 | 654 | @ <meta http-equiv="Content-Security-Policy" content="$default_csp" /> |
| 655 | 655 | @ <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 656 | 656 | @ <title>$<project_name>: $<title></title> |
| 657 | 657 | @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \ |
| 658 | 658 | @ href="$home/timeline.rss" /> |
| 659 | 659 | @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" /> |
| 660 | 660 | @ </head> |
| 661 | -@ <body class="$current_feature"> | |
| 661 | +@ <body class="$current_feature rpage-$requested_page cpage-$canonical_page"> | |
| 662 | 662 | ; |
| 663 | 663 | |
| 664 | 664 | /* |
| 665 | 665 | ** Returns the default page header. |
| 666 | 666 | */ |
| @@ -749,11 +749,11 @@ | ||
| 749 | 749 | /* |
| 750 | 750 | ** Initialize all the default TH1 variables |
| 751 | 751 | */ |
| 752 | 752 | static void style_init_th1_vars(const char *zTitle){ |
| 753 | 753 | const char *zNonce = style_nonce(); |
| 754 | - char *zDfltCsp; | |
| 754 | + char *zDfltCsp, *zSlash = 0; | |
| 755 | 755 | |
| 756 | 756 | zDfltCsp = style_csp(1); |
| 757 | 757 | /* |
| 758 | 758 | ** Do not overwrite the TH1 variable "default_csp" if it exists, as this |
| 759 | 759 | ** allows it to be properly overridden via the TH1 setup script (i.e. it |
| @@ -769,10 +769,15 @@ | ||
| 769 | 769 | Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL); |
| 770 | 770 | Th_Store("home", g.zTop); |
| 771 | 771 | Th_Store("index_page", db_get("index-page","/home")); |
| 772 | 772 | if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath); |
| 773 | 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)); | |
| 774 | 779 | Th_Store("csrf_token", g.zCsrfToken); |
| 775 | 780 | Th_Store("release_version", RELEASE_VERSION); |
| 776 | 781 | Th_Store("manifest_version", MANIFEST_VERSION); |
| 777 | 782 | Th_Store("manifest_date", MANIFEST_DATE); |
| 778 | 783 | Th_Store("compiler_name", COMPILER_NAME); |
| 779 | 784 |
| --- 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 |