Collection of themes/skins for the Fossil SCM

โŒˆโŒ‹ โŽ‡ branch:  Fossil Skins Extra


Check-in [18aea61ba2]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Support technotes
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 18aea61ba2cb9a8cdbc1b194a14e0802854a0419
User & Date: mario 2022-01-21 21:30:50
Context
2022-01-29
14:29
Generates sitemap.xml from wiki pages, doc files, technotes check-in: 94b31e1ce3 user: mario tags: trunk
2022-01-21
21:30
Support technotes check-in: 18aea61ba2 user: mario tags: trunk
2021-10-28
01:21
Enable wikitag saving (via new `fossil_exec()`) check-in: c09979b7a9 user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to extroot/fx_meta.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/php-cgi -dcgi.force_redirect=0
<?php
# encoding: utf-8
# api: cgi
# type: store
# category: template
# title: fx_meta cache
# description: Prepare twitter tags for wiki + doc pages
# version: 0.55
# state: alpha
# config:
#    { name: project-twitter, type: str, value: "", description: "Twitter handle for project (e.g. @sqlite1)" }
# access: admin
#
# Crafts a `fx_meta` database table to prepare twitter previews
# and image links, or other <meta> and <link> fields.








|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/php-cgi -dcgi.force_redirect=0
<?php
# encoding: utf-8
# api: cgi
# type: store
# category: template
# title: fx_meta cache
# description: Prepare twitter tags for wiki + doc pages
# version: 0.6
# state: alpha
# config:
#    { name: project-twitter, type: str, value: "", description: "Twitter handle for project (e.g. @sqlite1)" }
# access: admin
#
# Crafts a `fx_meta` database table to prepare twitter previews
# and image links, or other <meta> and <link> fields.
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80




81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103


104
105
106


107
108





109
110
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126
127
128
129
130
131
132

133
134
135
136
}

#-- init
db("CREATE TABLE IF NOT EXISTS fx_meta (name TEXT, meta TEXT)");
db("DELETE FROM fx_meta");
wiki_pages();
doc_pages();



#-- loop through pages
function wiki_pages() {
    foreach (db("SELECT substr(tagname,6) AS name FROM tag WHERE tagname LIKE 'wiki-%';") as $page) {
        $page = $page["name"];
        print "<li>$page\n";
        $q = "escapeshellarg";
        $html = shell_exec("fossil --nocgi wiki export --html {$q($page)} -R {$q($_SERVER['FOSSIL_REPOSITORY'])} 2>&1");
        insert_meta(
            "wiki?name=$page",
            meta_wiki($page, $html)
        );
    }
}





#-- scan *.md/wiki files
function doc_pages() {
    foreach (db("SELECT name FROM filename") as $page) {
        $fn = $page["name"];
        if (!preg_match("/\.(md|wiki)$/", $fn)) {
            continue;
        }
        print "<li>$fn\n";
        $q = "escapeshellarg";
        $md = shell_exec("fossil --nocgi cat {$q($fn)} -R {$q($_SERVER['FOSSIL_REPOSITORY'])} 2>&1");
        if (!$md) {
            continue;
        }
        $meta = meta_wiki($fn, $md);
        insert_meta("doc/trunk/$fn", $meta);
        insert_meta("doc/tip/$fn", $meta);
    }
}

# <meta> and <link>s for a wiki page
#  ยท wiki?name=PageName
function meta_wiki($name, $html) {


    $html = preg_replace("~<table.+?</table>~s", "", $html);
    $text = trim(preg_replace("~\s+~", " ", strip_tags($html)));
    $desc = substr($text, 0, 250);


    $twitter = trim(get_config("project-twitter", PROJECT_TWITTER), "@");
    $h = "h";





    if (preg_match("~<img[^>]+ src=[\"']? ([^\"'\s>]+)~x", $html, $uu) || preg_match("~(raw/\w+) \?m=image/~x", $html, $uu) or $uu=["","logo"]) {
        $img = $uu[1];
        if (strstr($img, "://")) {
        }
        elseif (preg_match("~raw/|doc/|^logo$~", $img)) {
            $img = $_SERVER["FOSSIL_SELF"] . $img;
        }
        elseif ($img[0] == "/") {
            $img = "https://$_SERVER[SERVER_NAME]$img";
        }

        $meta = <<<EOF
  <meta name="twitter:card" content="summary">
  <meta name="twitter:site" content="@$twitter">
  <meta name="twitter:creator" content="@$twitter">
  <meta name="twitter:title" content="{$h($name)}">
  <meta name="twitter:description" content="{$h($desc)}">
  <meta name="twitter:image" content="{$h($img)}">
  <meta name="twitter:image:src" content="{$h($img)}">
EOF;
        # could add FB (og:image, og:title, og:description, og:url) as well
    }
    else {
        $meta = "  <meta name=description content=\"{$h($desc)}\">\n";
    }

    $meta = preg_replace("~(?<!:)//+~", "/", $meta); // replace any double // in paths
    return $meta;
}








>



|
|
|


|

|
|



>
>
>
>














|







|
>
>



>
>


>
>
>
>
>










>

|












>




59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
}

#-- init
db("CREATE TABLE IF NOT EXISTS fx_meta (name TEXT, meta TEXT)");
db("DELETE FROM fx_meta");
wiki_pages();
doc_pages();
wiki_event();


#-- loop through pages
function wiki_pages($tagprefix="wiki-", $cli_args="", $url="wiki?name=", $long=0) {
    foreach (db("SELECT tagname AS name FROM tag WHERE tagname LIKE '$tagprefix%';") as $page) {
        $page = substr($page["name"], strpos($page["name"], "-") + 1);
        print "<li>$page\n";
        $q = "escapeshellarg";
        $html = shell_exec("fossil --nocgi wiki export $cli_args --html {$q($page)} -R {$q($_SERVER['FOSSIL_REPOSITORY'])} 2>&1");
        insert_meta(
            $url . $page,
            html_meta($page, $html, $long)
        );
    }
}
#-- technotes
function wiki_event() {
    wiki_pages("event-", "--technote", "technote/", 1);
}

#-- scan *.md/wiki files
function doc_pages() {
    foreach (db("SELECT name FROM filename") as $page) {
        $fn = $page["name"];
        if (!preg_match("/\.(md|wiki)$/", $fn)) {
            continue;
        }
        print "<li>$fn\n";
        $q = "escapeshellarg";
        $md = shell_exec("fossil --nocgi cat {$q($fn)} -R {$q($_SERVER['FOSSIL_REPOSITORY'])} 2>&1");
        if (!$md) {
            continue;
        }
        $meta = html_meta($fn, $md);
        insert_meta("doc/trunk/$fn", $meta);
        insert_meta("doc/tip/$fn", $meta);
    }
}

# <meta> and <link>s for a wiki page
#  ยท wiki?name=PageName
function html_meta($name, $html, $long=0) {

    # cleanup
    $html = preg_replace("~<table.+?</table>~s", "", $html);
    $text = trim(preg_replace("~\s+~", " ", strip_tags($html)));
    $desc = substr($text, 0, 250);
    
    # prepare tags
    $twitter = trim(get_config("project-twitter", PROJECT_TWITTER), "@");
    $h = "h";
    if ($long && preg_match("~<h\d>(.+)</h\d>~", $html, $uu)) {
        $name = $uu[1];  // technote pages require a headline
    }
    
    # check for image
    if (preg_match("~<img[^>]+ src=[\"']? ([^\"'\s>]+)~x", $html, $uu) || preg_match("~(raw/\w+) \?m=image/~x", $html, $uu) or $uu=["","logo"]) {
        $img = $uu[1];
        if (strstr($img, "://")) {
        }
        elseif (preg_match("~raw/|doc/|^logo$~", $img)) {
            $img = $_SERVER["FOSSIL_SELF"] . $img;
        }
        elseif ($img[0] == "/") {
            $img = "https://$_SERVER[SERVER_NAME]$img";
        }
        $summary = $long ? "summary_large_image" : "summary";
        $meta = <<<EOF
  <meta name="twitter:card" content="$summary">
  <meta name="twitter:site" content="@$twitter">
  <meta name="twitter:creator" content="@$twitter">
  <meta name="twitter:title" content="{$h($name)}">
  <meta name="twitter:description" content="{$h($desc)}">
  <meta name="twitter:image" content="{$h($img)}">
  <meta name="twitter:image:src" content="{$h($img)}">
EOF;
        # could add FB (og:image, og:title, og:description, og:url) as well
    }
    else {
        $meta = "  <meta name=description content=\"{$h($desc)}\">\n";
    }

    $meta = preg_replace("~(?<!:)//+~", "/", $meta); // replace any double // in paths
    return $meta;
}