GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — nullstack.github.io/src/Article.njs at master · MarciaA0693/nullstack.github.io

Expand file tree

/

Article.njs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
112 lines (102 loc) · 3.82 KB
/

Article.njs

Copy path

File metadata and controls

112 lines (102 loc) · 3.82 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import Nullstack from 'nullstack';
import './Article.scss';
import {existsSync, readFileSync} from 'fs';
import prismjs from 'prismjs';
import {Remarkable} from 'remarkable';
import meta from 'remarkable-meta';
import YAML from 'yaml';
import Arrow from '../icons/Arrow';
class Article extends Nullstack {
title = '';
html = '';
static async getArticleByKey({locale, key}) {
await import('prismjs/components/prism-jsx.min');
let path = `i18n/${locale}/articles/${key}.md`;
if(!existsSync(path)) {
path = `i18n/${locale}/articles/404.md`;
}
const text = readFileSync(path, 'utf-8');
const md = new Remarkable({
highlight: (code) => Prism.highlight(code, prismjs.languages.jsx, 'javascript')
});
md.use(meta);
md.use((md) => {
const originalRender = md.renderer.rules.link_open;
md.renderer.rules.link_open = function() {
let result = originalRender.apply(null, arguments);
const regexp = /href="([^"]*)"/;
const href = regexp.exec(result)[1];
if(!href.startsWith('/')) {
result = result.replace('>', ' target="_blank" rel="noopener">');
}
return result;
};
});
md.use((md) => {
md.renderer.rules.heading_open = function (tokens, i) {
const {content} = tokens[i+1];
const {hLevel} = tokens[i];
const id = content.toLowerCase().split(/[^a-z]/).join('-');
return `<h${hLevel} id="${id}"><a href="#${id}">`;
}
md.renderer.rules.heading_close = function (tokens, i) {
const {hLevel} = tokens[i];
return `</a></h${hLevel}>`;
}
});
return {
html: md.render(text),
...md.meta
}
}
static async getArticlesList({locale}) {
const file = readFileSync(`i18n/${locale}/components/Documentation.yml`, 'utf-8');
return YAML.parse(file);
}
async initiate({project, page, locale, params}) {
const article = await this.getArticleByKey({key: params.slug, locale});
Object.assign(this, article);
const { topics } = await this.getArticlesList({locale});
this.topics = topics
page.title = `${article.title} - ${project.name}`;
page.description = article.description;
if(article.status) {
page.status = 404;
}
}
renderLink({ title, href, router }) {
const active = router.url === href;
return (
<a href={href} class={`${active ? 'text-pink-500 dark:text-pink-500' : 'text-gray-500 dark:text-gray-300'} hover:text-pink-600 dark:hover:text-pink-400 block w-full`} onclick={{expanded: true}}> {title} </a>
)
}
renderTopic({ title, links }) {
return (
<div class="mb-3">
<h5> {title} </h5>
<nav>
{links.map((link) => <Link {...link} />)}
</nav>
</div>
)
}
render() {
return (
<section class="max-w-screen-xl mx-auto px-4 flex flex-wrap sm:flex-nowrap py-12 sm:py-24">
<button
onclick={{expanded: !this.expanded}}
class={`transition delay-300 fixed bottom-10 right-10 bg-pink-600 text-white shadow-xl rounded-full py-2 px-4 z-50 md:hidden ring-0 transform ${this.expanded ? 'rotate-180 transform' : ''}`}>
<Arrow size={20} />
</button>
<aside class={`w-full md:w-80 fixed top-0 left-0 md:relative z-40 md:z-auto bg-white dark:bg-gray-900 h-screen md:h-auto p-4 overflow-y-auto md:p-0 md:pr-4 transform pb-24 sm:pb-0 transition sm:transition-none delay-500 delay-0 ${this.expanded ? 'translate-y-0' : 'translate-y-full md:translate-y-0'}`}>
{this.topics?.map((topic) => <Topic {...topic} />)}
</aside>
<article class="w-full pb-24">
<h1 class="text-pink-600 text-4xl font-light block mb-8"> {this.title} </h1>
<div html={this.html} class="prose dark:prose-dark max-w-none" />
</article>
</section>
)
}
}
export default Article;
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.