# -*- 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.2.1 v
go.offline_build    no
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  7308d805cd69e6442e6e0d7079940d442eac470f \
                    sha256  80b821001c5fb92fa1beb0fc157d7b0fe1eedc96bfd62198b12a0062853feeb9 \
                    size    1036413

set kage_commit     f370402

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-06-15T06:30:45Z

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
}
