From e8415db2b8d66564a8cec7cd3e84ef6f23354324 Mon Sep 17 00:00:00 2001 From: Cole Goldsmith Date: Mon, 25 Sep 2023 16:56:03 -0500 Subject: [PATCH] Tutorial Page Layout (#13) * add styles for tutorial info, add helpers * add tutorial page layout --- src/css/doc.css | 9 ++++++++- src/css/ds-button.css | 6 ++++++ src/css/site.css | 1 + src/css/tutorial-info.css | 15 +++++++++++++++ src/helpers/stepcount.js | 7 +++++++ src/helpers/svg.js | 10 ++++++++++ src/img/colab.svg | 18 ++++++++++++++++++ src/layouts/tutorial.hbs | 11 +++++++++++ src/partials/article.hbs | 15 +++++++++------ src/partials/tutorial-info.hbs | 28 ++++++++++++++++++++++++++++ 10 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 src/css/tutorial-info.css create mode 100644 src/helpers/stepcount.js create mode 100644 src/helpers/svg.js create mode 100644 src/img/colab.svg create mode 100644 src/layouts/tutorial.hbs create mode 100644 src/partials/tutorial-info.hbs diff --git a/src/css/doc.css b/src/css/doc.css index 73203a2c..f9abf01a 100644 --- a/src/css/doc.css +++ b/src/css/doc.css @@ -939,7 +939,8 @@ padding: 0.25rem 0; } -.doc .conum[data-value] { +.doc .conum[data-value], +.doc .step { @include text-overline; color: var(--ds-text-inverse); @@ -963,6 +964,12 @@ display: none; } +.doc .step { + position: relative; + top: -0.25em; + margin-right: var(--ds-space-q); +} + .doc hr { border: solid var(--section-divider-color); border-width: 2px 0 0; diff --git a/src/css/ds-button.css b/src/css/ds-button.css index 06758a78..c79828a8 100644 --- a/src/css/ds-button.css +++ b/src/css/ds-button.css @@ -15,6 +15,10 @@ } } +a.ds-button:hover { + text-decoration: none; +} + /* icon button */ .ds-button--is-icon { height: var(--ds-space-5); @@ -24,10 +28,12 @@ .ds-button--leading-icon { margin-right: var(--ds-space-1); + display: flex; } .ds-button--trailing-icon { margin-left: var(--ds-space-1); + display: flex; } .ds-button--variant-outlined { diff --git a/src/css/site.css b/src/css/site.css index 8cd0fb8a..fc01feb8 100644 --- a/src/css/site.css +++ b/src/css/site.css @@ -23,3 +23,4 @@ @import "footer.css"; @import "highlight.css"; @import "print.css"; +@import "tutorial-info.css"; diff --git a/src/css/tutorial-info.css b/src/css/tutorial-info.css new file mode 100644 index 00000000..bbfc799d --- /dev/null +++ b/src/css/tutorial-info.css @@ -0,0 +1,15 @@ +.tutorial-info { + display: flex; + align-items: center; + gap: var(--ds-space-2h); + margin-bottom: var(--ds-space-3); +} + +.tutorial-info .info-item { + display: flex; + gap: var(--ds-space-1); +} + +.tutorial-info .tutorial-actions { + margin-left: auto; +} diff --git a/src/helpers/stepcount.js b/src/helpers/stepcount.js new file mode 100644 index 00000000..5e085e8f --- /dev/null +++ b/src/helpers/stepcount.js @@ -0,0 +1,7 @@ +'use strict' + +module.exports = (html) => { + const matches = html.toString().match(/class="step"/g) + if (!matches) return undefined + return matches.length +} diff --git a/src/helpers/svg.js b/src/helpers/svg.js new file mode 100644 index 00000000..df541a5e --- /dev/null +++ b/src/helpers/svg.js @@ -0,0 +1,10 @@ +'use strict' + +const fs = require('fs') +const path = require('path') + +module.exports = (iconName) => { + const pathName = path.join(__dirname, '/src/img/', iconName + '.svg') + const content = fs.readFileSync(pathName, 'utf8') + return content +} diff --git a/src/img/colab.svg b/src/img/colab.svg new file mode 100644 index 00000000..26996769 --- /dev/null +++ b/src/img/colab.svg @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file diff --git a/src/layouts/tutorial.hbs b/src/layouts/tutorial.hbs new file mode 100644 index 00000000..c5282ec1 --- /dev/null +++ b/src/layouts/tutorial.hbs @@ -0,0 +1,11 @@ + + + +{{> head defaultPageTitle='Untitled'}} + + +{{> header}} +{{> body}} +{{> footer}} + + diff --git a/src/partials/article.hbs b/src/partials/article.hbs index 81dac293..720eaada 100644 --- a/src/partials/article.hbs +++ b/src/partials/article.hbs @@ -1,7 +1,10 @@
-{{#with page.title}} -

{{{this}}}

-{{/with}} -{{{page.contents}}} -{{> pagination}} -
+ {{#with page.title}} +

{{{this}}}

+ {{/with}} + {{#if (eq page.layout 'tutorial')}} + {{> tutorial-info}} + {{/if}} + {{{page.contents}}} + {{> pagination}} + \ No newline at end of file diff --git a/src/partials/tutorial-info.hbs b/src/partials/tutorial-info.hbs new file mode 100644 index 00000000..6fb792cd --- /dev/null +++ b/src/partials/tutorial-info.hbs @@ -0,0 +1,28 @@ +
+ {{#with page.attributes.skill-level}} +
+ network_check + {{{this}}} +
+ {{/with}} + {{#with (stepcount page.contents)}} +
+ playlist_add_check + {{{this}}} Steps +
+ {{/with}} + {{#with page.attributes.time-commitment}} +
+ query_builder + {{{this}}} +
+ {{/with}} +
+ {{#with page.attributes.colab-link}} + +
{{{svg 'colab'}}}
+ Run this on Colab +
+ {{/with}} +
+
\ No newline at end of file