From 5c1d04acc68cce8ad99d9876a93165ebd03f70a3 Mon Sep 17 00:00:00 2001
From: Eloi Perdereau <eloi@perdereau.eu>
Date: Sat, 9 Nov 2019 02:38:30 +0100
Subject: [PATCH] setup netlify cms

---
 _authors/clara.md         |  4 +--
 _authors/lucas.md         |  4 +--
 _data/navigation.yml      | 17 +++++-----
 _includes/navigation.html |  4 +--
 _layouts/author.html      |  2 +-
 _layouts/default.html     | 12 +++++++
 _layouts/post.html        |  4 +--
 admin/config.yml          | 67 +++++++++++++++++++++++++++++++++++++++
 admin/index.html          | 14 ++++++++
 staff.markdown            |  2 +-
 10 files changed, 112 insertions(+), 18 deletions(-)
 create mode 100644 admin/config.yml
 create mode 100644 admin/index.html

diff --git a/_authors/clara.md b/_authors/clara.md
index 6ee2779..4e52b97 100644
--- a/_authors/clara.md
+++ b/_authors/clara.md
@@ -1,6 +1,6 @@
 ---
-short_name: clara
-name: Clara Terrier
+name: clara
+display_name: Clara Terrier
 position: Secrétaire
 ---
 tip tap top
diff --git a/_authors/lucas.md b/_authors/lucas.md
index 9e714a3..2fc800c 100644
--- a/_authors/lucas.md
+++ b/_authors/lucas.md
@@ -1,6 +1,6 @@
 ---
-short_name: lucas
-name: Lucas Schneider
+name: lucas
+display_name: Lucas Schneider
 position: Président
 ---
 Lulu président!
diff --git a/_data/navigation.yml b/_data/navigation.yml
index df9b21c..3a731b8 100644
--- a/_data/navigation.yml
+++ b/_data/navigation.yml
@@ -1,8 +1,9 @@
-- name: Home
-  link: /
-- name: About
-  link: /about.html
-- name: Blog
-  link: /blog.html
-- name: Staff
-  link: /staff.html
+items:
+  - name: Home
+    link: /
+  - name: About
+    link: /about.html
+  - name: Blog
+    link: /blog.html
+  - name: Staff
+    link: /staff.html
diff --git a/_includes/navigation.html b/_includes/navigation.html
index 65910e5..c684d5d 100644
--- a/_includes/navigation.html
+++ b/_includes/navigation.html
@@ -1,6 +1,6 @@
 <nav>
-  {% for item in site.data.navigation %}
-  <a href="{{ item.link }}" {% if page.url == item.link %}style="color: red;"{% endif %}>
+  {% for item in site.data.navigation.items %}
+  <a href="{{ site.baseurl }}{{ item.link }}" {% if page.url == item.link %}style="color: red;"{% endif %}>
     {{ item.name }}
   </a>
   {% endfor %}
diff --git a/_layouts/author.html b/_layouts/author.html
index 2e08aac..96c9ec3 100644
--- a/_layouts/author.html
+++ b/_layouts/author.html
@@ -1,5 +1,5 @@
 <!-- _layouts/author.html -->
-<h1>{{ page.name }}</h1>
+<h1>{{ page.display_name }}</h1>
 <h2>{{ page.position }}</h2>
 
 {{ content }}
diff --git a/_layouts/default.html b/_layouts/default.html
index e55958c..cf6af52 100644
--- a/_layouts/default.html
+++ b/_layouts/default.html
@@ -3,10 +3,22 @@
   <head>
     <meta charset="utf-8">
     <title>{{ page.title }}</title>
+    <script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
   </head>
   <body>
     {% include navigation.html %}
     {{ content }}
+  <script>
+    if (window.netlifyIdentity) {
+      window.netlifyIdentity.on("init", user => {
+        if (!user) {
+          window.netlifyIdentity.on("login", () => {
+            document.location.href = "/admin/";
+          });
+        }
+      });
+    }
+  </script>
   </body>
   <footer>
     default layout
diff --git a/_layouts/post.html b/_layouts/post.html
index e4acd37..c0f80ec 100644
--- a/_layouts/post.html
+++ b/_layouts/post.html
@@ -3,9 +3,9 @@
 
 <p>
   {{ page.date | date_to_string }}
-  {% assign author = site.authors | where: 'short_name', page.author | first %}
+  {% assign author = site.authors | where: 'name', page.author | first %}
   {% if author %}
-    - <a href="{{ author.url }}">{{ author.name }}</a>
+    - <a href="{{ author.url }}">{{ author.display_name }}</a>
   {% endif %}
 </p>
 
diff --git a/admin/config.yml b/admin/config.yml
new file mode 100644
index 0000000..53fae39
--- /dev/null
+++ b/admin/config.yml
@@ -0,0 +1,67 @@
+# config.yml
+
+backend:
+  name: git-gateway
+  branch: master # Branch to update (optional; defaults to master)
+media_folder: 'assets/uploads'
+collections:
+  - name: 'blog'
+    label: 'Blog'
+    folder: '_posts/'
+    create: true
+    slug: '{{year}}-{{month}}-{{day}}-{{slug}}'
+    editor:
+      preview: false
+    fields:
+      - { label: 'Layout', name: 'layout', widget: 'hidden', default: 'post' }
+      - { label: 'Title', name: 'title', widget: 'string' }
+      - { label: 'Publish Date', name: 'date', widget: 'datetime' }
+      - {
+          label: 'Author',
+          name: 'author',
+          widget: 'relation',
+          collection: 'authors',
+          displayFields: [display_name],
+          searchFields: [display_name],
+          valueField: 'name',
+        }
+      - { label: 'Body', name: 'body', widget: 'markdown' }
+  - name: 'authors'
+    label: 'Authors'
+    folder: '_authors/'
+    create: true
+    editor:
+      preview: false
+    fields:
+      - { label: 'Layout', name: 'layout', widget: 'hidden', default: 'author' }
+      - { label: 'Short Name', name: 'name', widget: 'string' }
+      - { label: 'Diplay Name', name: 'display_name', widget: 'string' }
+      - { label: 'Position', name: 'position', widget: 'string' }
+      - { label: 'Body', name: 'body', widget: 'markdown' }
+  - name: 'pages'
+    label: 'Pages'
+    editor:
+      preview: false
+    files:
+      - label: 'About Page'
+        name: 'about'
+        file: 'about.md'
+        fields:
+          - { label: 'Title', name: 'title', widget: 'hidden', default: 'about' }
+          - { label: 'Layout', name: 'title', widget: 'hidden', default: 'about' }
+          - { label: 'Body', name: 'body', widget: 'markdown' }
+  - name: "config"
+    label: "Config"
+    editor:
+      preview: false
+    files:
+      - label: "Navigation"
+        name: "navigation"
+        file: "_data/navigation.yml"
+        fields:
+          - label: "Navigation Items"
+            name: "items"
+            widget: "list"
+            fields:
+              - {label: Name, name: name, widget: string}
+              - {label: Link, name: link, widget: string}
diff --git a/admin/index.html b/admin/index.html
new file mode 100644
index 0000000..941e0fe
--- /dev/null
+++ b/admin/index.html
@@ -0,0 +1,14 @@
+<!-- admin/index.html -->
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <title>Content Manager</title>
+    <script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
+  </head>
+  <body>
+    <!-- Include the script that builds the page and powers Netlify CMS -->
+    <script src="https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js"></script>
+  </body>
+</html>
diff --git a/staff.markdown b/staff.markdown
index 572f3ef..83f1158 100644
--- a/staff.markdown
+++ b/staff.markdown
@@ -5,7 +5,7 @@ Staff
 =====
 
 {% for author in site.authors %}
-  [{{ author.name }}]({{ site.baseurl }}{{ author.url }})
+  [{{ author.display_name }}]({{ site.baseurl }}{{ author.url }})
   {{ author.position }}
   {{ author.content | markdownify }}
 
-- 
GitLab