package path;
 
use ASF::Util qw/walk_content_tree Load/;
use strict;
use warnings;

my $thrift_snippet_footer = <<'EOT'; # '$snippet' string magically refers to current snippet obj
<p class='snippet_footer'>
  This snippet was generated by {{ conf.title }}'s <strong>source tree docs</strong>:
  <a href="{{ $snippet.pretty_uri }}"</a>{{ $snippet.path }}</a>
</p>
EOT

my %thrift_args = (
    conf          => Load(join "", <DATA>), # make YAML __DATA__ below available in conf argument
    preprocess    => 1,                     # enable template preprocessing of .md files
    repo          => 'gitbox/thrift.git',   # set snippet default git repo (on gitbox)...
    template      => 'default.html',        # set common template argument (mainly for .md files)
    snippet_footer=> $thrift_snippet_footer,# append this string to each generated snipppet block
    quick_deps    => 1,                     # short-circuit deps processing to headers only
);

my $thrift_page_footer = $thrift_snippet_footer;
$thrift_page_footer =~ s/ snippet / page /; # full page 'snippets'

# order matters here: first match wins...  see http://www.apache.org/dev/cmsref#core-logic

our @patterns = (
    [qr!^/sitemap\.html$!,     sitemap => { %thrift_args, # %thrift_args as overrideable defaults
        headers   => { title => "Sitemap" },
        nest      => 1,
    }],
    [qr!^/index\.html$!,       snippet => { %thrift_args,
        view      => 'news_page',
        headers   => { title => "Home" },
    }],
    [qr!/index\.html$!,        sitemap => { %thrift_args }],
    [qr!^/(lib|test)/!,        snippet => { %thrift_args,
        view           => [qw/reconstruct trim_local_links single_narrative/],
        snippet_footer => $thrift_page_footer, # override: these are full pages not snippets
    }],
    [qr/\.md(?:text)?$/,       snippet => { %thrift_args,
        view      => 'single_narrative',
    }],
);

our %dependencies; # for /sitemap.html and /**/index.html pages whose title + url listings
                   # depend on the other files in the relevant content/ subdirectories.  We run
                   # the views for those files in offline mode for performance, since the titles
                   # and urls required do not depend on code snippet contents which take time to
                   # fetch.  We could do slightly better if we weren't interested in the actual
                   # build-generated output of those dependent files, which we aren't, but
                   # coding that up as a special case of the standard sitemap view isn't worth
                   # the trouble.
                   # Now watch me bother anyway just to see... ok done with 'quick_deps' support.
                   # Yay it's about a second faster on a full site build for thrift- go team!

walk_content_tree {
    if (/\.md(?:text)?$/ or m!/index\.html$! or m!^/test/!) {
        # basically grep s/^content//, glob("content/**/*.{md,mdtext}"),
        #                              glob("content/**/index.html"),
        #                              glob("content/test/**/*");
        # if perl's glob was as smart as zsh's glob
        push @{$dependencies{"/sitemap.html"}}, $_;
    }
    if (s!/index\.html$!!) {
        $dependencies{"$_/index.html"} = [
            grep s/^content//, glob("content$_/*.{md,mdtext}"),
                               glob("content$_/*/index.html")
        ];
    }
};

delete $dependencies{"/index.html"}; # the home page really doesn't depend on anything else

1;

__DATA__
# Thrift Site Variables
title: "Apache Thrift"
base_url: "http://thrift.apache.org"
git_repo: "https://github.com/apache/thrift"
release_url: "https://www.apache.org/dist/thrift"
mirror_url: "http://www.apache.org/dyn/closer.cgi?path="
jira_url: "http://issues.apache.org/jira/browse/THRIFT"

current_release: "0.13.0"
current_release_date: "2019-OCT-16"

# Apache ID, Name, Specialities, Timezone
committers: [
        [ "mcslee", "Mark Slee", "General vision and implementation", "-8" ],
        [ "dreiss", "David Reiss", "Everything, GIT configuration, performance", "-8" ],
        [ "aditya", "Aditya Agarwal", "C++ servers", "-8" ],
        [ "marck", "Marc Kwiatkowski", "C++ concurrency", "-8" ],
        [ "jwang", "James Wang", "C++ transports and processors", "-8" ],
        [ "cpiro", "Chris Piro", "Erlang", "-8" ],
        [ "bmaurer", "Ben Maurer", "Python data serialization", "-5" ],
        [ "kclark", "Kevin Clark", "Ruby implementation", "-8" ],
        [ "jake", "Jake Luciani", "Perl, JavaScript", "-5" ],
        [ "bryanduxbury", "Bryan Duxbury", "Compact Protocol, Java, Ruby", "-8" ],
        [ "esteve", "Esteve Fernandez", "Python, Twisted, async transports", "1" ],
        [ "todd", "Todd Lipcon", "Erlang, Java", "-8" ],
        [ "geechorama", "Andrew McGeachie", "Cocoa", "?" ],
        [ "molinaro", "Anthony Molinaro", "Erlang, Perl, autotools", "-8" ],
        [ "roger", "Roger Meier", "Continuous Integration, C++, C#, JavaScript, make cross and other stuff", "2" ],
        [ "jfarrell", "Jake Farrell", "Release Manager, Build, Client Publishing, Java, PHP, Ruby", "-5" ],
        [ "jensg", "Jens Geyer", "Delphi, C#/NetStd, Go, Graphviz, Haxe", "1" ],
        [ "carl", "Carl Yeksigian", "C#", "-5" ],
        [ "ra", "Randy Abernethy", "C++, Python, JavaScript, C#, what have you", "-8" ],
        [ "hcorg", "Konrad Grochowski", "C++, Python, Git, Continuous Integration", "1"],
        [ "nsuke", "Nobuaki Sukegawa ", "", "9"],
    ]


# Powered by: Company name, website
powered_by: [
        [ "Cloudera", "http://www.cloudera.com" ],
        [ "Evernote", "http://evernote.com" ],
        [ "Facebook", "http://www.facebook.com" ],
        [ "last.fm", "http://www.last.fm" ],
        [ "Mendeley", "http://www.mendeley.com" ],
        [ "OpenX", "http://www.openx.org" ],
		[ "Pinterest", "http://www.pinterest.com" ],
        [ "Quora", "http://www.quora.com" ],
        [ "RapLeaf", "http://www.rapleaf.com" ],
        [ "reCaptcha", "http://www.recaptcha.com" ],
        [ "Siemens", "http://www.siemens.com" ],
        [ "Uber", "http://uber.com" ]
    ]

# Apache Projects using Thrift: Project name, website
apache_projects: [
		[ "Aurora", "http://aurora.apache.org" ],
        [ "Camel", "http://camel.apache.org/" ],
		[ "Hadoop", "http://wiki.apache.org/hadoop/HDFS-APIs" ],
		[ "HBase", "http://wiki.apache.org/hadoop/Hbase/ThriftApi" ],
		[ "Parquet", "https://parquet.apache.org" ],
		[ "Storm", "http://storm.apache.org/" ]
    ]

# OSS Projects using Thrift: Project name, website
oss_projects: [
        [ "Microsoft Robust Distributed System Nucleus (rDSN)", "https://github.com/Microsoft/rDSN" ],
        [ "Twitter Finagle", "http://twitter.github.io/finagle/guide/Protocols.html" ],
        [ "Twitter Scrooge", "http://twitter.github.io/scrooge" ]
    ]

# external packages hosted elsewhere: 
# - Thrift target language
# - package manager name
# - link to package (URL) to most recent version
# - package control file (git source tree link)
# - package maintainer name
# - remarks
external_packages: [
		[ "(all)",       "Docker",        "https://hub.docker.com/_/thrift/",                                    "Dockerfile",                 "",                          "thrift compiler in /usr/local/bin/thrift" ],
        [ "ActionScript","Maven",         "https://repository.apache.org/#nexus-search;quick~libthrift-as3",     "lib/as3/build.xml",          "jking",                     "" ],
        [ "C (glib)",    "",              "",                                                                    "",                           "",                          "language has no package manager" ],
        [ "C++",         "",              "",                                                                    "",                           "",                          "see THRIFT-4800" ],
        [ "C#",          "NuGet",         "https://www.nuget.org/packages/ApacheThrift",                         "ApacheThrift.nuspec",        "jfarrell, codesf, jking",   "multi-framework nupkg for csharp and netcore" ],
        [ "Cocoa",       "",              "",                                                                    "",                           "",                          "deprecated on 0.12.0 - use swift" ],
        [ "Common LISP", "",              "",                                                                    "",                           "",                          "no official ASF package available" ],
		[ "D",           "dub",           "https://code.dlang.org/packages/apache-thrift",                       "dub.json",                   "jking",                     "" ],
        [ "Dart",        "Pub",           "https://pub.dartlang.org/packages/thrift",                            "lib/dart/pubspec.yaml",      "jking",                     "" ],
        [ ".NET Standard", "NuGet",       "https://www.nuget.org/packages/ApacheThrift",                         "ApacheThrift.nuspec",        "jfarrell, codesf, jking",   "multi-framework nupkg for csharp and netcore" ],
		[ "Erlang",      "Hex PM",        "https://hex.pm/packages?search=thrift&sort=downloads",                "",                           "",                          "no official ASF package available" ],
		[ "Haskell",     "Hackage",       "https://hackage.haskell.org/package/thrift",                          "lib/hs/thrift.cabal",        "jfarrell, clavoie, jking",  "" ],
		[ "Haxe",        "Haxelib",       "",                                                                    "lib/haxe/haxelib.json",      "jensg",                          "no package uploaded - see THRIFT-3036" ],
        [ "Go",          "",              "",                                                                    "",                           "",                          "no official ASF package available" ],
		[ "Java",        "Maven",         "https://repository.apache.org/#nexus-search;quick~org.apache.thrift", "lib/java/gradle.properties", "jking",                     "" ],
		[ "JavaScript",  "Bower",         "https://libraries.io/bower/thrift",                                   "bower.json",                 "",                          "" ],
        [ "Lua",         "LuaRocks",      "https://luarocks.org/modules/drauschenbach/thrift",                   "",                           "",                          "not official - stale at 0.10.0 - see THRIFT-4708" ],
		[ "Node.js",     "npm",           "https://www.npmjs.com/package/thrift",                                "package.json",               "jfarrell, wadey, jking",    "" ],
		[ "OCaml",       "opam",          "https://opam.ocaml.org/packages/thrift/",                             "lib/ocaml/opam",             "",                          "stale at 0.9.0 (community provided) - see THRIFT-4706" ],
		[ "Perl",        "CPAN",          "https://metacpan.org/release/Thrift",                                 "lib/perl/Makefile.PL",       "jking",                     "" ],
		[ "PHP",         "Packagist",     "https://packagist.org/packages/apache/thrift",                        "composer.json",              "jfarrell, bufferoverflow, jking",  "" ],
		[ "Python",      "pypi",          "https://pypi.python.org/pypi/thrift",                                 "lib/py/setup.py",            "jfarrell",                  "stale at 0.11.0 - see THRIFT-4687" ],
		[ "Ruby",        "Ruby Gem",      "https://rubygems.org/gems/thrift",                                    "lib/rb/Gemfile",             "jfarrell",                  "stale at 0.11.0 - see THRIFT-4707" ],
        [ "Rust",        "Cargo",         "https://crates.io/crates/thrift",                                     "lib/rs/cargo.toml",          "all thrift committers",     "" ],
        [ "Smalltalk",   "",              "",                                                                    "",                           "",                          "no official ASF package available" ],
        [ "Swift",       "",              "",                                                                    "",                           "",                          "no official ASF package available" ],
    ]
