|
1 | 1 | import Nullstack from 'nullstack'; |
| 2 | +import {readFileSync} from 'fs'; |
| 3 | +import YAML from 'yaml'; |
2 | 4 |
|
3 | 5 | class Documentation extends Nullstack { |
| 6 | + |
| 7 | + i18n = {}; |
| 8 | + |
| 9 | + static async geti18nByLocale({locale}) { |
| 10 | + const file = readFileSync(`pages/${locale}/${this.name}.yml`, 'utf-8'); |
| 11 | + return YAML.parse(file); |
| 12 | + } |
4 | 13 |
|
5 | | - prepare({project, page}) { |
6 | | - page.title = `Documentation - ${project.name}`; |
7 | | - page.description = 'Follow these steps and become a full-stack javascript developer!'; |
| 14 | + async initiate({project, page, locale}) { |
| 15 | + this.i18n = await this.geti18nByLocale({locale}); |
| 16 | + page.title = `${this.i18n.title} - ${project.name}`; |
| 17 | + page.description = this.i18n.description; |
8 | 18 | page.priority = 0.8; |
| 19 | + page.locale = locale || 'en-US'; |
9 | 20 | } |
10 | 21 |
|
11 | | - renderLink({title}) { |
| 22 | + renderLink({locale, title}) { |
12 | 23 | const href = '/' + title.toLowerCase().split(' ').join('-'); |
| 24 | + const prefix = locale != 'en-US' ? locale.toLowerCase() : ''; |
13 | 25 | return ( |
14 | | - <a href={href} class="xl x12 p3y bcm2t ci1"> {title} </a> |
| 26 | + <a href={prefix + href} class="xl x12 p3y bcm2t ci1"> {title} </a> |
15 | 27 | ) |
16 | 28 | } |
17 | 29 |
|
18 | | - renderTopic({title, description, children}) { |
| 30 | + renderTopic({title, description, links}) { |
19 | 31 | return ( |
20 | 32 | <div class="x12 m6y bcm2 p4x p4t p1b"> |
21 | 33 | <h2 class="x12 sm-fs6 md+fs8 m2b"> {title} </h2> |
22 | 34 | <p class="x12 fs4 m6b"> {description} </p> |
23 | | - <nav class="x12"> {children} </nav> |
| 35 | + <nav class="x12"> |
| 36 | + {links.map(link => <Link title={link} />)} |
| 37 | + </nav> |
24 | 38 | </div> |
25 | 39 | ) |
26 | 40 | } |
27 | 41 |
|
28 | 42 | render() { |
29 | 43 | return ( |
30 | 44 | <section class="x sm-p4x sm-p10y md+p20y"> |
31 | | - <h1 class="x12 sm-fs6 md+fs12 m2b"> Nullstack Documentation </h1> |
32 | | - <p class="x12 fs4"> Follow these steps and become a full-stack javascript developer! </p> |
33 | | - <Topic title="Core concepts" description="Start your journey in Nullstack with these basic concepts"> |
34 | | - <Link title="Getting started" /> |
35 | | - <Link title="Renderable components" /> |
36 | | - <Link title="Stateful components" /> |
37 | | - <Link title="Full-stack lifecycle" /> |
38 | | - <Link title="Server functions" /> |
39 | | - <Link title="Context" /> |
40 | | - <Link title="Routes and params" /> |
41 | | - <Link title="Two-way bindings" /> |
42 | | - </Topic> |
43 | | - <Topic title="Advanced concepts" description="These are concepts that you will most likely learn as you need in your projects"> |
44 | | - <Link title="Application Startup" /> |
45 | | - <Link title="Context data" /> |
46 | | - <Link title="Context environment" /> |
47 | | - <Link title="Context page" /> |
48 | | - <Link title="Context project" /> |
49 | | - <Link title="Context settings" /> |
50 | | - <Link title="Context secrets" /> |
51 | | - <Link title="Instance self" /> |
52 | | - <Link title="Instance Key" /> |
53 | | - <Link title="Server request and response" /> |
54 | | - <Link title="Styles" /> |
55 | | - <Link title="NJS file extension" /> |
56 | | - <Link title="Server-side rendering" /> |
57 | | - <Link title="Static site generation" /> |
58 | | - <Link title="Service Worker" /> |
59 | | - <Link title="How to deploy a Nullstack application" /> |
60 | | - </Topic> |
61 | | - <Topic title="Examples" description="The best way to learn Nullstack is by reading some code"> |
62 | | - <Link title="How to use MongoDB with Nullstack" /> |
63 | | - <Link title="How to use Google Analytics with Nullstack" /> |
64 | | - <Link title="How to use Facebook Pixel with Nullstack" /> |
65 | | - </Topic> |
| 45 | + <h1 class="x12 sm-fs6 md+fs12 m2b"> {this.i18n.heading} </h1> |
| 46 | + <p class="x12 fs4"> {this.i18n.tagline} </p> |
| 47 | + {this.i18n.topics.map((topic) => <Topic {...topic} />)} |
66 | 48 | </section> |
67 | 49 | ) |
68 | 50 | } |
|
0 commit comments