From 9f0755df4b6413c1fd6e49f3a11bbabe4bc7c3b4 Mon Sep 17 00:00:00 2001
From: krachzack <hello@phstadler.com>
Date: Mon, 11 Dec 2023 16:05:55 +0100
Subject: [PATCH] feat: add new Q/A type for non-language facts

Add the new card type, integrate it into the build and index.html. Also change the layout for all cards a bit so that the card type on the top floats, and the main content clears. For this purpose a new class .prompt has been added to the translations, as well as the new card type. The new facts type additionally shows the subdeck on the right for context.
---
 build/apkg.py                                 | 12 +++++++---
 package.json                                  |  4 +++-
 src/components/facts.css                      |  6 +++++
 src/components/global.css                     | 19 ++++++++++++---
 src/index.html                                |  7 ++++++
 src/templates/facts/q_a/back.html             | 13 +++++++++++
 src/templates/facts/q_a/front.html            | 23 +++++++++++++++++++
 src/templates/hanzi/read/front.html           |  2 +-
 src/templates/hanzi/write/front.html          |  2 +-
 src/templates/molaoshi/hear/front.html        |  2 +-
 src/templates/molaoshi/read_hanzi/front.html  |  2 +-
 src/templates/molaoshi/read_pinyin/front.html |  2 +-
 src/templates/molaoshi/speak/front.html       |  2 +-
 src/templates/molaoshi/write/front.html       |  2 +-
 14 files changed, 84 insertions(+), 14 deletions(-)
 create mode 100644 src/components/facts.css
 create mode 100644 src/templates/facts/q_a/back.html
 create mode 100644 src/templates/facts/q_a/front.html

diff --git a/build/apkg.py b/build/apkg.py
index 5b90a62..74fd95b 100755
--- a/build/apkg.py
+++ b/build/apkg.py
@@ -8,12 +8,18 @@ import sys
 templates = [
   (
     # if this key phrase is found on the front template
-    "anki-template-hanyu-speak",
+    "facts-q-a-front",
     # then use front.html and back.html in this directory for the card type
-    "templates/molaoshi/speak",
+    "templates/facts/q_a",
     # and for skeleton apkg use this front HTML
-    "anki-template-hanyu-speak-front {{Deutsch}}",
+    "facts-q-a-front {{Front}}",
     # and this back HTML
+    "facts-q-a-back {{Back}}"
+  ),
+  (
+    "anki-template-hanyu-speak",
+    "templates/molaoshi/speak",
+    "anki-template-hanyu-speak-front {{Deutsch}}",
     "anki-template-hanyu-speak-back {{Pīnyīn}}"
   ),
   (
diff --git a/package.json b/package.json
index 4836188..7c3f26e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "anki-template-hanyu",
-  "version": "1.0.1",
+  "version": "1.1.0",
   "description": "Anki template for learning to write, speak and understand Mandarin Chinese",
   "repository": "https://github.com/tapirbug/anki-template-hanyu",
   "author": "Philipp Stadler <hello@phstadler.com>",
@@ -25,6 +25,8 @@
   },
   "source": [
     "src/index.html",
+    "src/templates/facts/q_a/front.html",
+    "src/templates/facts/q_a/back.html",
     "src/templates/hanzi/read/front.html",
     "src/templates/hanzi/read/back.html",
     "src/templates/hanzi/write/front.html",
diff --git a/src/components/facts.css b/src/components/facts.css
new file mode 100644
index 0000000..85dc9ec
--- /dev/null
+++ b/src/components/facts.css
@@ -0,0 +1,6 @@
+.facts-question, .facts-answer {
+  text-align: left;
+  max-width: 60em;
+  margin-left: auto;
+  margin-right: auto;
+}
diff --git a/src/components/global.css b/src/components/global.css
index 2f4c36f..920f468 100644
--- a/src/components/global.css
+++ b/src/components/global.css
@@ -8,13 +8,26 @@
   text-align: center;
 }
 
-.exercise-kind {
+.exercise-kind, .exercise-category {
   font-size: 0.7rem;
   color: rgba(0, 0, 0, 0.5);
-  text-align: left;
+  margin-bottom: 1.5em;
+}
+
+.exercise-kind {
+  float: left;
+}
+
+.exercise-category {
+  float: right;
+}
+
+.prompt {
+  clear: both;
 }
 
-.nightMode .exercise-kind {
+.nightMode .exercise-kind,
+.nightMode .exercise-category {
   color: rgba(255, 255, 255, 0.5);
 }
 
diff --git a/src/index.html b/src/index.html
index 34da6ee..32a4297 100644
--- a/src/index.html
+++ b/src/index.html
@@ -9,6 +9,13 @@
 <body>
   <h1>Overview</h1>
 
+  <h2>templates/facts</h2>
+  <h3>Q/A</h3>
+  <h4>Front</h4>
+  <a href="templates/facts/q_a/front.html">read/front.html</a>
+  <h4>Back</h4>
+  <a href="templates/facts/q_a/back.html">read/back.html</a>
+
   <h2>templates/hanzi</h2>
   <h3>Read</h3>
   <h4>Front</h4>
diff --git a/src/templates/facts/q_a/back.html b/src/templates/facts/q_a/back.html
new file mode 100644
index 0000000..2b5c824
--- /dev/null
+++ b/src/templates/facts/q_a/back.html
@@ -0,0 +1,13 @@
+<div class="exercise back facts-q-a-back">
+  {{FrontSide}}
+
+  <hr id="answer">
+
+  <div class="facts-answer">
+    {{Back}}
+  </div>
+</div>
+
+<script type="module">
+  import '../../../components/debug'
+</script>
\ No newline at end of file
diff --git a/src/templates/facts/q_a/front.html b/src/templates/facts/q_a/front.html
new file mode 100644
index 0000000..a035d5f
--- /dev/null
+++ b/src/templates/facts/q_a/front.html
@@ -0,0 +1,23 @@
+<style>
+  @import url(../../../components/global.css);
+  @import url(../../../components/facts.css);
+</style>
+
+<div class="exercise front facts-q-a-front">
+  <aside class="exercise-kind">
+    {{Card}}
+  </aside>
+  <aside class="exercise-category">
+    {{Subdeck}}
+  </aside>
+
+  <div class="prompt facts-question">
+    {{Front}}
+  </div>
+
+  <include src="src/components/notice/notice.html"></include>
+</div>
+
+<script type="module">
+  import '../../../components/debug'
+</script>
\ No newline at end of file
diff --git a/src/templates/hanzi/read/front.html b/src/templates/hanzi/read/front.html
index a525950..161aedc 100644
--- a/src/templates/hanzi/read/front.html
+++ b/src/templates/hanzi/read/front.html
@@ -7,7 +7,7 @@
     {{Card}}
   </aside>
 
-  <dl class="translations">
+  <dl class="prompt translations">
     <dt>
       汉字
     </dt>
diff --git a/src/templates/hanzi/write/front.html b/src/templates/hanzi/write/front.html
index d4f61a8..81b5ca0 100644
--- a/src/templates/hanzi/write/front.html
+++ b/src/templates/hanzi/write/front.html
@@ -7,7 +7,7 @@
     {{Card}}
   </aside>
 
-  <dl class="translations">
+  <dl class="prompt translations">
     <dt>
       Key word
     </dt>
diff --git a/src/templates/molaoshi/hear/front.html b/src/templates/molaoshi/hear/front.html
index bfd29f5..3a5de6f 100644
--- a/src/templates/molaoshi/hear/front.html
+++ b/src/templates/molaoshi/hear/front.html
@@ -7,7 +7,7 @@
     {{Card}}
   </aside>
 
-  <dl class="translations">
+  <dl class="prompt translations">
     <dt>
       汉语
     </dt>
diff --git a/src/templates/molaoshi/read_hanzi/front.html b/src/templates/molaoshi/read_hanzi/front.html
index 0777487..8adeaad 100644
--- a/src/templates/molaoshi/read_hanzi/front.html
+++ b/src/templates/molaoshi/read_hanzi/front.html
@@ -7,7 +7,7 @@
     {{Card}}
   </aside>
 
-  <dl class="translations">
+  <dl class="prompt translations">
     <dt>
       汉字
     </dt>
diff --git a/src/templates/molaoshi/read_pinyin/front.html b/src/templates/molaoshi/read_pinyin/front.html
index bbc03de..89e3a46 100644
--- a/src/templates/molaoshi/read_pinyin/front.html
+++ b/src/templates/molaoshi/read_pinyin/front.html
@@ -7,7 +7,7 @@
     {{Card}}
   </aside>
 
-  <dl class="translations">
+  <dl class="prompt translations">
     <dt>
       Pīnyīn
     </dt>
diff --git a/src/templates/molaoshi/speak/front.html b/src/templates/molaoshi/speak/front.html
index af56673..53e5b05 100644
--- a/src/templates/molaoshi/speak/front.html
+++ b/src/templates/molaoshi/speak/front.html
@@ -7,7 +7,7 @@
     {{Card}}
   </aside>
 
-  <dl class="translations">
+  <dl class="prompt translations">
     <dt>
       Deutsch
     </dt>
diff --git a/src/templates/molaoshi/write/front.html b/src/templates/molaoshi/write/front.html
index 8da076a..8085971 100644
--- a/src/templates/molaoshi/write/front.html
+++ b/src/templates/molaoshi/write/front.html
@@ -7,7 +7,7 @@
     {{Card}}
   </aside>
 
-  <dl class="translations">
+  <dl class="prompt translations">
     <dt>
       Deutsch
     </dt>
-- 
GitLab