# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           golang 1.0

go.setup            github.com/tamnd/kage 0.3.12 v
go.offline_build    no
go.toolchain_min    1.26.5
revision            0

description         \
    Clone websites for offline viewing, with JavaScript stripped out

long_description    \
    {*}${description}. kage drives a real browser, snapshots the settled DOM, \
    removes scripts, localizes assets, and writes a static mirror that can be \
    browsed offline or packed into a ZIM archive.

categories          www
installs_libs       no
license             MIT
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

checksums           rmd160  ed0c7291a0346056d7a3732d8aa4ce0a70bfc708 \
                    sha256  02f388764950037948444ec55b12e967741c94f352d0997c363821872876a3b8 \
                    size    1160835

set kage_commit     3583ec3

post-extract {
    reinplace "s|go build|${go.bin} build|" ${worksrcpath}/Makefile
}

build.cmd           make
build.target        build
build.args          VERSION=v${version} \
                    COMMIT=${kage_commit} \
                    DATE=2026-08-10T07:12:37Z

notes               "kage clone requires Chrome or Chromium on the host."

destroot {
    set kage_doc_dir ${prefix}/share/doc/${name}

    xinstall -m 0755 ${worksrcpath}/bin/${name} ${destroot}${prefix}/bin/
    xinstall -d ${destroot}${kage_doc_dir}
    xinstall -m 0644 ${worksrcpath}/README.md \
                    ${worksrcpath}/CHANGELOG.md \
                    ${worksrcpath}/LICENSE \
                    ${destroot}${kage_doc_dir}

    copy ${worksrcpath}/docs/content ${destroot}${kage_doc_dir}/docs
    copy ${worksrcpath}/docs/static ${destroot}${kage_doc_dir}/static

    file mkdir ${worksrcpath}/_completions

    foreach _shell { bash fish zsh } {
        system -W ${worksrcpath}/_completions \
            "../bin/${name} completion ${_shell} > ${name}.${_shell}"
    }

    xinstall -d ${destroot}${prefix}/share/bash-completion/completions
    copy ${worksrcpath}/_completions/${name}.bash \
        ${destroot}${prefix}/share/bash-completion/completions/${name}

    xinstall -d ${destroot}${prefix}/share/zsh/site-functions
    copy ${worksrcpath}/_completions/${name}.zsh \
        ${destroot}${prefix}/share/zsh/site-functions/_${name}

    xinstall -d ${destroot}${prefix}/share/fish/vendor_completions.d
    copy ${worksrcpath}/_completions/${name}.fish \
        ${destroot}${prefix}/share/fish/vendor_completions.d/${name}.fish
}
