#####################################################################
#
# A-A-P file for making AsciiDoc web site.
# (you can obtain A-A-P from http://www.a-a-p.org)
#
# Stuart Rackham <srackham@gmail.com>
#####################################################################

:execute ../../common.aap

WEB_NAME = asciidoc

LAYOUT ?= layout1

# Various document locations.
PROJ_DIR = ../..
DOCS_DIR = $PROJ_DIR/doc
LOCAL_WEB = ~/tmp/asciidoc-web # Local web marshalling location.

# List of web pages.
WEB_ROOT =
    a2x.1
    asciidoc-docbook-xsl
    asciidoc-graphviz-sample
    asciimathml
    asciidocapi
    CHANGELOG
    epub-notes
    faq
    index
    INSTALL
    latex-backend
    latex-bugs
    latexmathml
    manpage
    music-filter
    latex-filter
    publishing-ebooks-with-asciidoc
    README
    README-website
    source-highlight-filter
    support
    testasciidoc
    userguide
    version83
    newtables
    newlists
    slidy
    slidy-example
WEB_PAGES = $*(WEB_ROOT).html
WEB_SOURCE = $*(WEB_ROOT).txt

# Web site specific pages to spell check.
SPELL_CHECK =
    index.txt
    README-website.txt
    support.txt

# Accompanying documents in DOCS_DIR.
DOCS_ROOT =
    asciidoc
    asciidoc.1
DOCS =
    $*(DOCS_ROOT).txt
    $*(DOCS_ROOT).html
    $*(DOCS_ROOT).css-embedded.html
    $*(DOCS_ROOT).xml
    asciidoc.pdf
    asciidoc.epub
    asciidoc.1
    article.txt article.html article-standalone.html
    book.txt book.html
    book-multi.txt book-multi.html
    docbook-xsl.css
    book.epub
    article.pdf
    latexmath.pdf

# Client applications.
@if OSTYPE == 'posix':
    ASPELL = `program_path("aspell")`
@else:
    :print ERROR: Unsupported operating system $OSTYPE
    :exit

:syseval which xmllint | :assign XMLLINT    # Validates XML.

ASCIIDOC = python ../../asciidoc.py
# AsciiDoc options to generate documentation HTML.
ASCIIDOC_HTML =
    $ASCIIDOC -b xhtml11 -f $(LAYOUT).conf -a icons -a badges -a revnumber=$(VERS)@ -a revdate="$(DATE)@" -a max-width=70em

:rule %.html : %.txt $(LAYOUT).conf
    @if target in ('userguide.html','faq.html'):
        # User guide has author, revision, date in header.
        opts = -a toc -a numbered
    @elif target == 'index.html':
        # Index has description and keywords meta tags.
        opts = -a index-only
    @elif target in ('manpage.html','a2x.1.html'):
        opts = -d manpage
    @elif target == 'asciimathml.html':
        opts = -a asciimath
    @elif target == 'latexmathml.html':
        opts = -a latexmath
    @else:
        opts =
    @if target in ('index.html','INSTALL.html','asciidocapi.html','testasciidoc.html','publishing-ebooks-with-asciidoc.html'):
        opts += -a toc -a toclevels=1
    :sys $ASCIIDOC_HTML $opts $(source[0])
    @if _no.XMLLINT:
        :sys $XMLLINT --nonet --noout --valid $target
    @else:
        :print WARNING: xmllint(1) unavailable: skipping validation

slidy.html : slidy.txt
    :sys $ASCIIDOC $(source[0])

slidy-example.html : slidy-example.txt
    :sys $ASCIIDOC $(source[0])

all: $(WEB_PAGES)

copy: all
    # Copy to local web page.
    :sys rm -rf $LOCAL_WEB/*
    :sys mkdir -p $LOCAL_WEB/images/icons/callouts
    :sys cp $WEB_PAGES $LOCAL_WEB
    :sys cp $WEB_SOURCE $LOCAL_WEB
    :sys cp *.css $LOCAL_WEB
    :sys cp *.js $LOCAL_WEB
    :execute $PROJ_DIR/main.aap distribution    # Make docs and tarball.
    :sys cp $DOCS_DIR/$*DOCS $LOCAL_WEB
    # Copy images.
    :sys cp $DOCS_DIR/images/*.png $LOCAL_WEB/images/
    :sys cp $DOCS_DIR/images/icons/*.png $LOCAL_WEB/images/icons/
    :sys cp $DOCS_DIR/images/icons/callouts/*.png $LOCAL_WEB/images/icons/callouts/
    # Copy chunked User Guide.
    :sys rm -rf $LOCAL_WEB/chunked/
    :sys mkdir -p $LOCAL_WEB/chunked/
    :sys cp $DOCS_DIR/asciidoc.chunked/*.html $LOCAL_WEB/chunked/
    :sys cp $DOCS_DIR/asciidoc.chunked/*.css $LOCAL_WEB/chunked/
    :sys cp -R $DOCS_DIR/asciidoc.chunked/images $LOCAL_WEB/chunked/
    :sys cp music?.* $LOCAL_WEB
    :sys cp sample?.png $LOCAL_WEB
    :sys cp latex?.png $LOCAL_WEB
    :sys cp *__*.png $LOCAL_WEB

clean:
    :del {f} $WEB_PAGES
    :del {f} *.bak          # Remove aspell backups.

spell: $(SPELL_CHECK)
    # Interactively spell check all files.
    @if _no.ASPELL:
        @for s in source_list:
            :sys {i} $ASPELL check -p ./$(WEB_NAME)-website.dict $s
    @else:
        :print WARNING: aspell(1) unavailable, skipping spell checking
