variables:
    GUIDE_ROOT: $YAMLURL                # Used by guide.py to pass to markdown.template

    # Created by root.node@gmail.com
    # https://console.developers.google.com/apis/api/customsearch.googleapis.com/overview?project=big-query-1009
    # This key is also used by https://code.gramener.com/s.anand/exceltranslate
    # Used by proxyhandler/ and translate/
    GOOGLE_API_KEY: AIzaSyBsSkZb3hxciFp0ZB3KLqO1-aQW-K-hqSw

log:
    root:
        level: INFO                     # Just log info, not debug

app:
  settings:
    login_url: /$YAMLURL/auth/db        # Use DB Auth by default -- it works offline
    autoreload: False
    debug: False
    xsrf_cookie_kwargs:
        httponly: false                 # Allow JavaScript access to cookies

import:
  subdirs:
    path: '*/gramex.yaml'              # Import gramex.yaml from immediate subdirs
    namespace: [url, schedule, cache, import]
  ui:
    path: $GRAMEXAPPS/ui/gramex.yaml    # Import UI app
    YAMLURL: $YAMLURL/ui/

handlers:
    FileHandler:
        ignore:
            - ".*"                      # Hide only dotfiles, allow gramex.yaml

url:
    # Default FileHandler. Serve all .md files as Markdown
    markdown:
        pattern: /$YAMLURL/(.*)
        handler: FileHandler
        priority: -0.5          # Lower than new handlers (0), higher than default (-1)
        kwargs:
            path: $YAMLPATH
            default_filename: README.md
            index: true
            transform: &MARKDOWN_TO_HTML
                "*.md":
                    function: guide.markdown_template(content, handler)
                    encoding: utf-8
                    headers:
                        Content-Type: text/html
            headers: &HEADERS
                Cache-Control: public, max-age=300
    markdown-g1:
        pattern: /$YAMLURL/g1/([a-z0-0]+)
        handler: FileHandler
        kwargs:
            path: $GRAMEXAPPS/ui/node_modules/g1/docs/*.md
            transform: *MARKDOWN_TO_HTML
            headers: *HEADERS
    markdown-g1-default:
        pattern: /$YAMLURL/g1/(.*)
        handler: FileHandler
        kwargs:
            path: $GRAMEXAPPS/ui/node_modules/g1/docs/
            default_filename: README.md
            transform: *MARKDOWN_TO_HTML
            headers: *HEADERS
    # The welcome page is the first page that's served when users login.
    # Normally, / points README.md. Make /welcome point to the static welcome page
    welcome:
        pattern: /$YAMLURL/welcome
        handler: FileHandler
        kwargs:
            path: $YAMLPATH/index.html
            headers: *HEADERS
    # The final *computed* gramex.yaml configuration
    final-config:
        pattern: /$YAMLURL/final-config
        handler: FunctionHandler
        kwargs:
            function: guide.config
            headers: *HEADERS
    # Just serve the root gramex.yaml file
    root-config:
        pattern: /$YAMLURL/root.gramex.yaml
        handler: FileHandler
        kwargs:
            path: $GRAMEXPATH/gramex.yaml
            headers:
                Content-Type: text/plain
                <<: *HEADERS

    # Static files are cached on the browser
    static:
        pattern: /$YAMLURL/(.*.css|.*.js)
        handler: FileHandler
        kwargs:
            path: $YAMLPATH/*
            headers:
                Cache-Control: public, max-age=300

    # /path.source shows the raw file as plain text
    source:
        pattern: /$YAMLURL/(.*)\.source
        handler: FileHandler
        kwargs:
            path: $YAMLPATH
            headers:
                Content-Type: text/plain
                headers: *HEADERS
