Collection of themes/skins for the Fossil SCM

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


Check-in [e228e3b3dc]

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

Overview
Comment:Prepare meta tags for wiki pages
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e228e3b3dca79f759c7045a84ad9e9b66c06a0cd
User & Date: mario 2021-10-09 20:30:50
Context
2021-10-10
07:30
Utilize --nocgi for fossil wiki extraction, fixed some varnames/rx. check-in: 50b1405382 user: mario tags: trunk
2021-10-09
20:30
Prepare meta tags for wiki pages check-in: e228e3b3dc user: mario tags: trunk
2021-09-19
10:16
Add survey tbl display tool. check-in: a08c7b5ce3 user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added extroot/fx_meta.



















































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
#!/usr/bin/php-cgi -dcgi.force_redirect=0
<?php
# encoding: utf-8
# api: cgi
# type: store
# category: template
# title: meta tags (twitter)
# description: populate fx_meta with wiki page summaries
# version: 0.1
# state: alpha
# config: -
#
# Crafts a `fx_meta` database table to prepare twitter previews
# and image links, or other <meta> and <link> fields.
# Which can then be embedded into the header via:
#
#   <th1>  try { query {SELECT meta FROM fx_meta WHERE name=$current_page} { print $meta } }  </th1>
#
# Should be useable as extroot/ hook or ordinary cron script (with
# repo file as parameter).
#


#-- cli or admin usage
if (!empty($_SERVER["argv"][1])) {
    $_SERVER["FOSSIL_REPOSITORY"] = $_SERVER["argv"][1];
}
elseif (!strstr($_SERVER["FOSSIL_CAPABILITIES"], "s")) {
    die("Run as cron, or as admin");
}



#-- database (== fossil repo)
function db($sql="", $params=[]) {
    static $db;
    if (empty($db)) {
        $db = new PDO("sqlite:$_SERVER[FOSSIL_REPOSITORY]");
    }
    if ($params) {
        $stmt = $db->prepare($sql);
        $stmt->execute($params);
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
    else {
        return $db->query($sql)->fetchAll();
    }
}
function h($s) {
    return htmlspecialchars($h, "utf-8", ENT_QUOTES);
}

#-- init
db("CREATE TABLE IF NOT EXISTS fx_meta (name TEXT, meta TEXT)");
db("DELETE FROM fx_meta");
wiki_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"];
        $q = "escapeshellarg";
        $html = `fossil wiki export --html {$q($page)} -R {$q($_SERVER['FOSSIL_REPOSITORY'])}`;
        db(
            "INSERT INTO fx_meta (name, meta) VALUES (?,?)",
            ["wiki?name=$page", meta_wiki($name, $html)]
        );
    }
}


# <meta> and <link>s for a wiki page
#  ยท wiki?name=PageName
function meta_wiki($name, $html) {
    $html = preg_replace("~<table.+</table>~s", "", $html);
    $text = preg_replace("~\s+~", " ", strip_tags($html));
    $desc = substr($text, 0, 250);
    $h = "h";
    if (preg_match("~(raw/\w+)\?m=image/~", $html, $uu) || preg_match("~(?:!\[.+]\(|<img.+?src=\S*)(raw/\w+)~", $html, $uu)) {
        $img = $uu[1];
        $meta = <<<EOF
    <meta name="twitter:card" content="summary">
    <meta name="twitter:site" content="@sqlite">
    <meta name="twitter:creator" content="@fossilscm">
    <meta name="twitter:title" content="{$h($page)}">
    <meta name="twitter:description" content="{$h($page)}">
    <meta name="twitter:image" content="{$h($img)}">
    <meta name="twitter:image:src" content="{$h($img)}">
EOF;
    }
    else {
        $meta = "    <meta name=description content=\"{$h($desc)\">\n";
    }
    return $meta;
}

# <link> for files
#  ยท finfo?name=feeds/aggregator.css
#  ยท file?name=feeds/aggregator.css&ci=4cebd63e48afb573
#  ยท info/224e3f34a9f1fe11a22e7edd77120a87ff746b7f2afd7f7398ce212a471877ee
function meta_file($name, $content) {
    $meta = "<link rel='vcs alternate raw' href='raw/...' type='text/plain' content-disposition='inline; filename=$name'>";
    $meta = "<meta name='vcs alternate filename' href='file.cpp'>";
}