import metalsmith from "metalsmith";
import webpack from "metalsmith-webpack";
import reactTemplate from "metalsmith-react-templates";
import excerpts from "metalsmith-excerpts";
import collections from "metalsmith-collections";
import branch from "metalsmith-branch";
import permalinks from "metalsmith-permalinks";

metalsmith(__dirname)
  .metadata({
    site: {
      title: "公民學院",
      url: "http://blog.citizenedu.tw/",
      description: "沃草公民學院是為所有人準備的人文學習、討論平台。我們不但小國小民，更要好國好民。",
    }
  })
  .use(collections({
    posts: {
      pattern: "posts/**.html"
    },
    columns: {
      pattern: "columns/**.html"
    },
    subjects: {
      pattern: "subjects/**.html"
    },
    tags: {
      pattern: "tags/**.html"
    },
    guide: {
      pattern: "guide/**.html"
    },
    authors: {
      pattern: "authors/**.html"
    }
  }))
  .use(branch("posts/**.html")
    .use(permalinks({
      pattern: "posts/:path",
      relative: false
    }))
  )
  .use(branch("!posts/**.html")
    .use(branch("!index.html")
      .use(permalinks({
        relative: false
      }))
    )
  )
  .use(excerpts())
  .use(reactTemplate({
    directory: "app",
    baseFile: "index.html",
    nonStatic: true
  }))
  .use(webpack({
    entry: "./app/app.es6",
    output: {
      path: __dirname + "/build/js",
      filename: "bundle.js"
    },
    module: {
      loaders: [
        { test: /\.(js|es6)$/, exclude: /node_modules/, loader: "babel-loader" },
        { test: /\.css$/, loader: "style-loader!css-loader" },
        { test: /\.(jpg|png)$/, loader: "url-loader" },
        { test: /\.(json)$/, loader: "json-loader" },
      ]
    },
    resolve: {
      extensions: ["", ".web.js", ".js", ".jsx", ".es6"]
    }
  }))
  .build(function (err) {
    if (err) throw err;
    console.log("Site build complete.");
  });

@@ -551,32 +551,82 @@
  %22posts/**.html%22
+,%0A      sortBy: %22created_at%22,%0A      reverse: true,
 %0A    %7D,%0A    colu

fix posts sorting