Overview
Comment:feat(tag-page): only update tag page if necessary
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA3-256: 3827dbbc8ece94994e5badb81c4198ead284e0f4bd09df0516551e13129c0cd3
User & Date: dbohdan on 2020-04-29 10:37:49
Other Links: manifest | tags
Context
2020-04-29
10:37
feat(tag-page): only update tag page if necessary Leaf check-in: 3827dbbc8e user: dbohdan tags: trunk
2020-04-08
17:27
feat(css): give .img-responsive bottom margin check-in: 43dbd86ff3 user: dbohdan tags: trunk
Changes

Modified tag-page/tag-page.tcl from [511210adf9] to [c08bc78ba5].

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
..
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
#! /usr/bin/env tclsh
# Generate a tag page for a Fossil wiki.
# Copyright (c) 2020 D. Bohdan.
# License: MIT.
# Typical usage in an open Fossil repository:
# $ ./tag-page.tcl . | fossil wiki commit 'Special: Pages by tag'

package require Tcl 8.6

proc page-tags pageText {
    if {[regexp -nocase {\n\[Tags\]\([^)]+\): ([^\.\n]+)} $pageText _ tags]} {
        return [lmap x [split $tags ,] {string trim $x}]
    } else {
        return {}
    }
}


proc group-by-tag pages {
    set grouped {}

    foreach {name contents} $pages {
        if {$contents in {{} \n}} continue

................................................................................
        foreach tag [page-tags $contents] {
            dict lappend grouped $tag $name
        }
    }

    return $grouped
}


proc entities text {
    return [string map {
        & &amp
        < &lt;
        > &gt;
        \" &quot;
        ' &#039;
    } $text]
}


proc markdown-list {grouped level} {
    set markdown {}
    set prefix [string repeat # $level]

    foreach {tag pages} $grouped {
        set section [list "$prefix [entities $tag]"]

        foreach page $pages {
            set link [expr {
                [regexp {[\(\)\[\]<>"'&]} $page]
................................................................................
}


proc fossil args {
    exec -ignorestderr fossil {*}$args
}









proc tag-page database-file {




    set pages {}
    foreach name [split [fossil wiki ls ${database-file}] \n] {
        lappend pages $name [fossil wiki export $name]
    }
    
    set grouped [group-by-tag $pages]
    set sorted [lsort -stride 2 -index 0 -nocase $grouped]
    return [markdown-list $sorted 3]
}










# If this is the main script...
if {[info exists argv0] && ([file tail [info script]] eq [file tail $argv0])} {
    puts {# Pages by tag}
    puts {## Contents}
    puts {## Tags}
    puts [tag-page {*}$argv]
}





|



|
|





>







 







>











>
|

<







 







>
>
>
>
>
>
>
>
|
>
>
>
>

|


|


|
|
>
>
>
>
>
>
>
>
>



<
<
<
|

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
..
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
#! /usr/bin/env tclsh
# Generate a tag page for a Fossil wiki.
# Copyright (c) 2020 D. Bohdan.
# License: MIT.
# Typical usage in an open Fossil repository:
# $ ./tag-page.tcl . 'Special: Pages by tag'

package require Tcl 8.6

proc page-tags text {
    if {[regexp -nocase {\n\[Tags\]\([^)]+\): ([^\.\n]+)} $text _ tags]} {
        return [lmap x [split $tags ,] {string trim $x}]
    } else {
        return {}
    }
}


proc group-by-tag pages {
    set grouped {}

    foreach {name contents} $pages {
        if {$contents in {{} \n}} continue

................................................................................
        foreach tag [page-tags $contents] {
            dict lappend grouped $tag $name
        }
    }

    return $grouped
}


proc entities text {
    return [string map {
        & &amp
        < &lt;
        > &gt;
        \" &quot;
        ' &#039;
    } $text]
}


proc markdown-list {grouped prefix} {
    set markdown {}


    foreach {tag pages} $grouped {
        set section [list "$prefix [entities $tag]"]

        foreach page $pages {
            set link [expr {
                [regexp {[\(\)\[\]<>"'&]} $page]
................................................................................
}


proc fossil args {
    exec -ignorestderr fossil {*}$args
}


proc update-page {name contents} {
    set old [fossil wiki export $name]
    if {$contents eq $old} return
    fossil wiki commit $name << $contents
}


proc tag-page repo {
    set lines {}

    lappend lines {# Pages by tag} {## Contents} {## Tags}

    set pages {}
    foreach name [split [fossil wiki ls $repo] \n] {
        lappend pages $name [fossil wiki export $name]
    }

    set grouped [group-by-tag $pages]
    set sorted [lsort -stride 2 -index 0 -nocase $grouped]
    lappend lines [markdown-list $sorted ###]

    return [join $lines \n]
}


proc main {repo page-name} {
    set contents [tag-page $repo]
    update-page ${page-name} $contents
}


# If this is the main script...
if {[info exists argv0] && ([file tail [info script]] eq [file tail $argv0])} {



    puts [main {*}$argv]
}