From 83e0c28d1844c83f01c9c23dd064c29b9a9d6090 Mon Sep 17 00:00:00 2001
From: Karthik Balakrishnan <karthikb351@gmail.com>
Date: Tue, 20 Sep 2016 22:10:01 +0530
Subject: [PATCH] Refactor  - Get games from spreadsheet  - Push to collections, not data files  - Setup template for collection item

---
 _config.yml                |  8 +++++++-
 index.html                 | 14 --------------
 signup.html                | 13 -------------
 _data/games.yml            | 49 +++++++++++++++++++++++--------------------------
 _includes/footer.html      |  2 +-
 _layouts/game.html         | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 _scripts/fetch_manifest.js | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 pages/index.html           | 15 +++++++++++++++
 pages/signup.html          | 13 +++++++++++++
 9 files changed, 224 insertions(+), 58 deletions(-)

diff --git a/_config.yml b/_config.yml
index 92a7b77..86efc49 100644
--- a/_config.yml
+++ a/_config.yml
@@ -209,4 +209,10 @@
 compress_html:
   clippings: all
   ignore:
-    envs: development+    envs: development
+
+
+collections:
+  games:
+    output: true
+    permalink: /game/:path/diff --git a/index.html b/index.html
deleted file mode 100644
index 78a05d1..0000000 100644
--- a/index.html
+++ /dev/null
@@ -1,14 +1,0 @@
----
-layout: single
-title: Hello!
----
-
-We are a Bangalore-based board games collective.
-
-Which is just a fancy way of saying we are a couple of friends who play board games and have a lot of free time.
- 
-We've still got a bit of work to do on the site so until then, find us on Facebook, Twitter and Telegram.
-
-<a class="btn btn--facebook" href="https://facebook.com/ReRollBLR"><i class="fa fa-fw fa-facebook"></i> ReRoll Games</a>
-<a class="btn btn--twitter" href="https://twitter.com/ReRoll_BLR"><i class="fa fa-fw fa-twitter"></i> @ReRoll_BLR</a>
-<a class="btn btn--linkedin" href="https://telegram.me/reroll"><i class="fa fa-fw fa-paper-plane" aria-hidden="true"></i> @ReRoll</a>
diff --git a/signup.html b/signup.html
deleted file mode 100644
index 840d830..0000000 100644
--- a/signup.html
+++ /dev/null
@@ -1,13 +1,0 @@
----
-layout: single
-title: Sign Up!
-permalink: /signup
----
-
-{% include mailchimp.html %}
-
-
-<h2>You can also follow us at</h2>
-<a class="btn btn--facebook" href="https://facebook.com/ReRollBLR"><i class="fa fa-fw fa-facebook"></i> ReRoll Games</a>
-<a class="btn btn--twitter" href="https://twitter.com/ReRoll_BLR"><i class="fa fa-fw fa-twitter"></i> @ReRoll_BLR</a>
-<a class="btn btn--linkedin" href="https://telegram.me/reroll"><i class="fa fa-fw fa-paper-plane" aria-hidden="true"></i> @ReRoll</a>
diff --git a/_data/games.yml b/_data/games.yml
index 2698d5a..a763b5e 100644
--- a/_data/games.yml
+++ a/_data/games.yml
@@ -1,31 +1,22 @@
 ---
+# All games are here - https://docs.google.com/spreadsheets/d/1Mk8dK_QESBX3GQ8e2F7wPtdF74V9gw0ohhU5UHGJK5Y
 events:
-  "humming-tree-2":
-    - cash_n_guns
-    - love_letter
-    - spaceteam
-    - machi_koro
-    - citadels
-    - jaipur
-    - codenames
-    - saboteur
-    - avalon
-    - greed
-    - age_of_war
-    - dixit
-    - takenoko
-# https://www.boardgamegeek.com/xmlapi2/thing?id=184491&type=boardgame
-board_game_geek:
-  spaceteam: 184491
-  love_letter: 129622
-  cash_n_guns: 155362
-  machi_koro: 143884
-  citadels: 478
-  jaipur: 54043
-  codenames: 178900
-  saboteur: 9220
-  avalon: 128882
-  greed: 151247
-  age_of_war: 155695
-  dixit: 39856
-  takenoko: 70919
+  humming-tree-2:
+    games:
+      - cash_n_guns
+      - love_letter
+      - spaceteam
+      - machi_koro
+      - citadels
+      - jaipur
+      - codenames
+      - saboteur
+      - avalon
+      - greed
+      - age_of_war
+      - dixit
+      - takenoko
+    venue: The Humming Tree
+    date: 
+    tickets:
+    diff --git a/_includes/footer.html b/_includes/footer.html
index 1949a13..ab9faa4 100644
--- a/_includes/footer.html
+++ a/_includes/footer.html
@@ -21,5 +21,5 @@
   </ul>
 </div>
 
-<div class="page__footer-copyright">&copy; {{ site.time | date: '%Y' }} {{ site.name | default: site.title }}. Run by <a href="https://www.facebook.com/kaushik.narayan.39"><i class="fa fa-fw fa-facebook"></i> Kaushik</a>, <a href="https://twitter.com/karthikb351"><i class="fa fa-fw fa-twitter"></i>  @karthikb351</a> and <a href="https://twitter.com/mithunbalraj"><i class="fa fa-fw fa-twitter"></i>  @mithunbalraj</a>.
+<div class="page__footer-copyright">&copy; {{ site.time | date: '%Y' }} {{ site.name | default: site.title }} run by <a href="https://www.facebook.com/kaushik.narayan.39"><i class="fa fa-fw fa-facebook"></i> Kaushik</a>, <a href="https://twitter.com/karthikb351"><i class="fa fa-fw fa-twitter"></i>  @karthikb351</a> and <a href="https://twitter.com/mithunbalraj"><i class="fa fa-fw fa-twitter"></i>  @mithunbalraj</a>.
 </div>diff --git a/_layouts/game.html b/_layouts/game.html
new file mode 100644
index 0000000..5aee5c2 100644
--- /dev/null
+++ a/_layouts/game.html
@@ -1,0 +1,77 @@
+---
+layout: default
+---
+
+{% include base_path %}
+
+{% if (page.header.overlay_color or page.header.overlay_image) or page.header.image %}
+  {% include page__hero.html %}
+{% endif %}
+
+{% if page.url != "/" and site.breadcrumbs %}
+  {% unless paginator %}
+    {% include breadcrumbs.html %}
+  {% endunless %}
+{% endif %}
+
+<div id="main" role="main">
+  {% include sidebar.html %}
+
+  <article class="page" itemscope itemtype="http://schema.org/CreativeWork">
+    {% if page.title %}<meta itemprop="headline" content="{{ page.title | markdownify | strip_html | strip_newlines | escape_once }}">{% endif %}
+    {% if page.excerpt %}<meta itemprop="description" content="{{ page.excerpt | markdownify | strip_html | strip_newlines | escape_once }}">{% endif %}
+    {% if page.date %}<meta itemprop="datePublished" content="{{ page.date | date: "%B %d, %Y" }}">{% endif %}
+    {% if page.modified %}<meta itemprop="dateModified" content="{{ page.modified | date: "%B %d, %Y" }}">{% endif %}
+
+    <div class="page__inner-wrap">
+      {% unless page.header.overlay_color or page.header.overlay_image %}
+        <header>
+          {% if page.title %}<h1 class="page__title" itemprop="headline">{{ page.title | markdownify | remove: "<p>" | remove: "</p>" }}</h1>{% endif %}
+          {% if page.read_time %}
+            <p class="page__meta"><i class="fa fa-clock-o" aria-hidden="true"></i> {% include read-time.html %}</p>
+          {% endif %}
+        </header>
+      {% endunless %}
+
+      <section class="page__content" itemprop="text">
+        <img src="{{ page.game.thumbnail }}">
+        <p>{{ page.game.description }}</p>
+        {% if page.link %}<div><a href="{{ page.link }}" class="btn">{{ site.data.ui-text[site.locale].ext_link_label | default: "Direct Link" }}</a></div>{% endif %}
+      </section>
+
+      <footer class="page__meta">
+        {% if site.data.ui-text[site.locale].meta_label %}
+          <h4 class="page__meta-title">{{ site.data.ui-text[site.locale].meta_label }}</h4>
+        {% endif %}
+        {% include page__taxonomy.html %}
+        {% if page.modified %}
+          <p class="page__date"><strong><i class="fa fa-fw fa-calendar" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}</strong> <time datetime="{{ page.modified | date: "%Y-%m-%d" }}">{{ page.modified | date: "%B %d, %Y" }}</time></p>
+        {% elsif page.date %}
+          <p class="page__date"><strong><i class="fa fa-fw fa-calendar" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}</strong> <time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date: "%B %d, %Y" }}</time></p>
+        {% endif %}
+      </footer>
+
+      {% if page.share %}{% include social-share.html %}{% endif %}
+
+      {% include post_pagination.html %}
+    </div>
+
+    {% if site.comments.provider and page.comments %}
+      {% include comments.html %}
+    {% endif %}
+  </article>
+
+  {% comment %}<!-- only show related on a post page when not disabled -->{% endcomment %}
+  {% if page.id and page.related and site.related_posts.size > 0 %}
+    <div class="page__related">
+      {% if site.data.ui-text[site.locale].related_label %}
+        <h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h4>
+      {% endif %}
+      <div class="grid__wrapper">
+        {% for post in site.related_posts limit:4 %}
+          {% include archive-single.html type="grid" %}
+        {% endfor %}
+      </div>
+    </div>
+  {% endif %}
+</div>diff --git a/_scripts/fetch_manifest.js b/_scripts/fetch_manifest.js
new file mode 100644
index 0000000..aebf1d3 100644
--- /dev/null
+++ a/_scripts/fetch_manifest.js
@@ -1,0 +1,91 @@
+var Tabletop = require('tabletop');
+var async = require('async');
+var YAML = require('yamljs');
+var fs = require('fs');
+
+// all options are optional
+var options = {
+  timeout: 10000, // timeout of 10s (5s is the default)
+
+  // see https://github.com/cujojs/rest/blob/master/docs/interceptors.md#module-rest/interceptor/retry
+  retry: {
+    initial: 100,
+    multiplier: 2,
+    max: 15e3
+  }
+}
+
+var bgg = require('bgg')(options);
+
+var sheets = [
+{
+  name: "Board Games",
+  url: 'https://docs.google.com/spreadsheets/d/1Mk8dK_QESBX3GQ8e2F7wPtdF74V9gw0ohhU5UHGJK5Y/pubhtml',
+  sheetName: "Inventory",
+}
+];
+
+async.forEach(sheets, function (item, callback){
+
+  function writeData(dataSet, tabletop) {
+    var keys = tabletop.sheets(item.sheetName)['column_names'];
+    var gamesList = tabletop.sheets(item.sheetName).toArray(); //list of rows
+
+    async.forEach(gamesList, function (game, cb) {
+      var bgg_id = game[keys.indexOf('bgg_id')];
+      bgg('thing', {type: 'boardgame', id: bgg_id})
+      .then(function(results){
+
+        bgg_response = results['items']['item'];
+        var name = "";
+        for (var i = 0; i < bgg_response.name.length; i++) {
+          var n = bgg_response.name[i];
+          if(n.type == 'primary')
+            name = n.value;
+        }
+
+        var gameData = {
+          name: name,
+          description: bgg_response.description,
+          bgg_id: bgg_response.id,
+          thumbnail: bgg_response.thumbnail,
+          image: bgg_response.image,
+          minPlayers: bgg_response.minplayers.value,
+          maxPlayers: bgg_response.maxplayers.value,
+          yearPublished: bgg_response.yearpublished.value,
+          playTime: bgg_response.playingtime.value,
+          short_id: game[keys.indexOf('short_id')],
+          comment: game[keys.indexOf('comment')],
+          buy_url: game[keys.indexOf('buy_url')],
+          buy_type: game[keys.indexOf('buy_type')],
+        };
+        var yamlFrontMatter = 
+          "---\n"+
+          YAML.stringify( {
+          layout: 'game',
+          title: gameData.name,
+          game: gameData,
+        }, 2)
+          +"\n---";
+        
+        var file = '_games/'+game[keys.indexOf('short_id')]+'.md';
+        fs.writeFileSync(file, yamlFrontMatter);
+      
+        console.log(yamlFrontMatter);
+        
+        cb();
+      });
+
+    }, function(err){
+        callback();
+    });
+  }
+
+  Tabletop.init( { key: item.url,
+    callback: writeData,
+    wanted: [item.sheetName],
+    simpleSheet: false } )
+
+  }, function(err) {
+    console.log('Done');
+  });  diff --git a/pages/index.html b/pages/index.html
new file mode 100644
index 0000000..f676543 100644
--- /dev/null
+++ a/pages/index.html
@@ -1,0 +1,15 @@
+---
+layout: single
+title: Hello!
+permalink: /
+---
+
+We are a Bangalore-based board games collective.
+
+Which is just a fancy way of saying we are a couple of friends who play board games and have a lot of free time.
+ 
+We've still got a bit of work to do on the site so until then, find us on Facebook, Twitter and Telegram.
+
+<a class="btn btn--facebook" href="https://facebook.com/ReRollBLR"><i class="fa fa-fw fa-facebook"></i> ReRoll Games</a>
+<a class="btn btn--twitter" href="https://twitter.com/ReRoll_BLR"><i class="fa fa-fw fa-twitter"></i> @ReRoll_BLR</a>
+<a class="btn btn--linkedin" href="https://telegram.me/reroll"><i class="fa fa-fw fa-paper-plane" aria-hidden="true"></i> @ReRoll</a>
diff --git a/pages/signup.html b/pages/signup.html
new file mode 100644
index 0000000..840d830 100644
--- /dev/null
+++ a/pages/signup.html
@@ -1,0 +1,13 @@
+---
+layout: single
+title: Sign Up!
+permalink: /signup
+---
+
+{% include mailchimp.html %}
+
+
+<h2>You can also follow us at</h2>
+<a class="btn btn--facebook" href="https://facebook.com/ReRollBLR"><i class="fa fa-fw fa-facebook"></i> ReRoll Games</a>
+<a class="btn btn--twitter" href="https://twitter.com/ReRoll_BLR"><i class="fa fa-fw fa-twitter"></i> @ReRoll_BLR</a>
+<a class="btn btn--linkedin" href="https://telegram.me/reroll"><i class="fa fa-fw fa-paper-plane" aria-hidden="true"></i> @ReRoll</a>
--
rgit 0.1.5