all repos — h3rald @ v10

The sources of https://h3rald.com

scripts/lint.min

 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
 106
"output" ls-r ("\.html" match?) filter :html-files

(
    symbol check-links
    (str :contents ==> quot :result)
    (
        () @result
        contents "<a.+?href=\"(.+?)(?:#.+?)?\".*?>.+?</a>" search-all :hrefs
        hrefs (
            1 get :href
            href :resolved-href
            ; Check internal links
            (href "^\/" match?)
                (
                    (href "\..+$" match? not)
                        (
                            (href "\/$" match?)
                                ("$#$#" (href "index.html") =% @resolved-href)
                                ("$#/$#" (href "index.html") =% @resolved-href)
                            if
                        )
                    when
                    "$#$#" ("output" resolved-href) =% @resolved-href
                    (resolved-href file? not)
                        (
                            (result resolved-href in? not)
                                (resolved-href result append @result)
                            when
                        )
                    when
                )
            when
            #|(href "^https?:\/\/(?:www.)?h3rald.com" match?)
                (
                    (result href in? not)
                        (href result append @result)
                    when
                )
            when|#
        ) foreach
    )
) ::

(
    symbol check-images
    (str :contents ==> quot :result)
    (
        () @result
        contents "<img.+?src=\"(.+?)\".*?>" search-all :srcs
        srcs (
            1 get :src
            src :resolved-src
           ; Check internal images
           (src "^\/" match?) 
                (
                    "$#$#" ("output" resolved-src) =% @resolved-src
                    (resolved-src file? not)
                        (
                            (result resolved-src in? not)
                                (resolved-src result append @result)
                            when
                        )
                    when
                )
            when
            (src "^https?:\/\/(?:www.)?h3rald.com" match?)
                (
                    (result src in? not)
                        (src result append @result)
                    when
                )
            when
        ) foreach
    )
) ::

; Check all output files for internal broken links and images
html-files
(
    :file
    file fread :contents
    contents check-links :broken-links
    contents check-images :broken-images
    broken-links size :n-links
    broken-images size :n-images
    (((n-links 0 >)(n-images 0 >)) ||)
        (
            "=> $#" (file) =% puts!
            (n-links 0 >)
                ("   -> $# Invalid Links:" (n-links) =% puts!)
            when
            broken-links (
                :target
                "     - $#" (target) =% puts!
            ) foreach
            (n-images 0 >)
                ("   -> $# Invalid Images:" (n-images) =% puts!)
            when
            broken-images (
                :target
                "     - $#" (target) =% puts!
            ) foreach
        )
    when
) foreach