FROM pandoc/extra:latest-ubuntu

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    curl \
    fonts-noto-core \
    fonts-noto-color-emoji \
    fonts-noto-cjk \
    fonts-noto-mono \
    fonts-dejavu \
    fonts-inconsolata \
    fonts-lmodern \
    fonts-texgyre \
    fonts-texgyre-math \
    fonts-cmu \
    fontconfig \
    unzip && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

ARG LIBERTINUS_VERSION=7.051

RUN mkdir -p /usr/share/fonts/opentype/newcomputermodern && \
    curl -L -o /tmp/newcomputermodern.zip "https://mirrors.ctan.org/fonts/newcomputermodern.zip" && \
    unzip -j /tmp/newcomputermodern.zip "newcomputermodern/otf/*.otf" -d /usr/share/fonts/opentype/newcomputermodern && \
    rm /tmp/newcomputermodern.zip

RUN mkdir -p /usr/share/fonts/opentype/libertinus && \
    curl -L -o /tmp/libertinus.zip "https://github.com/alerque/libertinus/releases/download/v${LIBERTINUS_VERSION}/Libertinus-${LIBERTINUS_VERSION}.zip" && \
    unzip -j /tmp/libertinus.zip "Libertinus-${LIBERTINUS_VERSION}/static/OTF/*.otf" -d /usr/share/fonts/opentype/libertinus && \
    rm /tmp/libertinus.zip

RUN mkdir -p /usr/share/fonts/opentype/texgyre && \
    cp /usr/share/texmf/fonts/opentype/public/tex-gyre/*.otf /usr/share/fonts/opentype/texgyre/

RUN mkdir -p /usr/share/fonts/truetype/twemoji && \
    curl -L -o /tmp/twemoji-colr.zip "https://mirrors.ctan.org/fonts/twemoji-colr.zip" && \
    unzip -j /tmp/twemoji-colr.zip "twemoji-colr/TwemojiMozilla.ttf" -d /usr/share/fonts/truetype/twemoji && \
    rm /tmp/twemoji-colr.zip

RUN mkdir -p /usr/share/fonts/truetype/custom

COPY ./fonts/ /usr/share/fonts/truetype/custom/

RUN find /usr/share/fonts/truetype/custom -type f -exec chmod 644 {} \; && \
    fc-cache -f -v
