Skip to content

Commit e5716d2

Browse files
Merge pull request #1 from TipsCode/upgrade-nullstack
📌 upgrade nullstack
2 parents 94fb077 + 8335222 commit e5716d2

File tree

11 files changed

+109
-282455
lines changed

11 files changed

+109
-282455
lines changed

client.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Nullstack from 'nullstack';
2+
3+
import Application from './src/Application';
4+
5+
const context = Nullstack.start(Application);
6+
7+
context.start = async function start() {
8+
// https://nullstack.app/application-startup
9+
};
10+
11+
export default context;

index.js

-5
This file was deleted.

package.json

+7-10
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,24 @@
66
"license": "ISC",
77
"scripts": {
88
"start": "npx nullstack start",
9-
"build": "npx nullstack build --mode=ssg --output=docs",
10-
"tailwind": "npx tailwindcss-cli build -o src/tailwind.css"
9+
"build": "npx nullstack build --mode=ssg --output=docs"
1110
},
1211
"dependencies": {
13-
"@tailwindcss/typography": "^0.4.0",
12+
"@tailwindcss/typography": "0.5.9",
1413
"babel-eslint": "^10.1.0",
1514
"dotenv": "^8.2.0",
1615
"eslint": "^7.22.0",
1716
"eslint-config-airbnb": "^18.2.1",
1817
"eslint-plugin-import": "^2.22.1",
1918
"eslint-plugin-jsx-a11y": "^6.4.1",
2019
"eslint-plugin-react": "^7.22.0",
21-
"nullstack": "~0.11.0",
20+
"nullstack": "~0.17.0",
2221
"poisonicon": "^0.1.2",
22+
"postcss": "^8.4.12",
23+
"postcss-loader": "^7.0.1",
2324
"prismjs": "^1.23.0",
2425
"remarkable": "^2.0.1",
25-
"remarkable-meta": "^1.0.1"
26-
},
27-
"devDependencies": {
28-
"autoprefixer": "^10.4.4",
29-
"postcss": "^8.4.12",
30-
"tailwindcss": "^3.0.24"
26+
"remarkable-meta": "^1.0.1",
27+
"tailwindcss": "^3.0.0"
3128
}
3229
}

server.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Nullstack from 'nullstack';
2+
import { readdirSync, readFileSync } from 'fs';
3+
import prismjs from 'prismjs';
4+
import { Remarkable } from 'remarkable';
5+
import meta from 'remarkable-meta';
6+
import Application from './src/Application';
7+
8+
const context = Nullstack.start(Application);
9+
10+
context.start = async function start() {
11+
await import('prismjs/components/prism-jsx.min');
12+
const articles = readdirSync('articles');
13+
const md = new Remarkable({
14+
// eslint-disable-next-line no-undef
15+
highlight: (code) => Prism.highlight(code, prismjs.languages.jsx, 'javascript'),
16+
});
17+
md.use(meta);
18+
md.use((md) => {
19+
const originalRender = md.renderer.rules.link_open;
20+
md.renderer.rules.link_open = (...args) => {
21+
let result = originalRender(...args);
22+
const regexp = /href="([^"]*)"/;
23+
const href = regexp.exec(result)[1];
24+
if (!href.startsWith('/')) {
25+
result = result.replace('>', ' target="_blank" rel="noopener">');
26+
}
27+
return result;
28+
};
29+
});
30+
context.articles = articles.map((name) => {
31+
const markdown = readFileSync(`articles/${name}`, 'utf-8');
32+
const [slug] = name.split('.');
33+
const content = md.render(markdown);
34+
const { date: dateString, ...meta } = md.meta;
35+
const date = new Date(dateString);
36+
const readingTime = ~~(content.split(' ').length / 200);
37+
return { slug, content, date, readingTime, ...meta };
38+
}).sort((a, b) => b.date - a.date);
39+
};
40+
41+
export default context;

src/Application.njs

+21-58
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1+
import '../tailwind.css';
12
import './Application.scss';
23
import Nullstack from 'nullstack';
3-
import { readdirSync, readFileSync } from 'fs';
4-
import prismjs from 'prismjs';
5-
import { Remarkable } from 'remarkable';
6-
import meta from 'remarkable-meta';
74
import Home from './home/Home';
85
import Articles from './articles/Articles';
96
import Article from './article/Article';
@@ -14,46 +11,11 @@ import MiniCourse from './mini-course/MiniCourse';
1411
import MiniCourseThankPage from './delivery-mini-course/MiniCourseThankPage';
1512
import MiniCourseClasses from './delivery-mini-course/MiniCourseClasses';
1613
import PageVideoDepo from './delivery-mini-course/PageVideoDepo';
17-
1814
import GoogleAnalytics from './layout/GoogleAnalytics';
1915
import FacebookPixel from './layout/FacebookPixel';
2016

21-
import FacePixelFullStack from './course-fullstack-turbo/FacePixelFullStack';
22-
import FacePixelReact from './course-react-pro/FacePixelReact';
23-
2417
class Application extends Nullstack {
2518

26-
static async start(context) {
27-
await import('prismjs/components/prism-jsx.min');
28-
const articles = readdirSync('articles');
29-
const md = new Remarkable({
30-
// eslint-disable-next-line no-undef
31-
highlight: (code) => Prism.highlight(code, prismjs.languages.jsx, 'javascript'),
32-
});
33-
md.use(meta);
34-
md.use((md) => {
35-
const originalRender = md.renderer.rules.link_open;
36-
md.renderer.rules.link_open = (...args) => {
37-
let result = originalRender(...args);
38-
const regexp = /href="([^"]*)"/;
39-
const href = regexp.exec(result)[1];
40-
if (!href.startsWith('/')) {
41-
result = result.replace('>', ' target="_blank" rel="noopener">');
42-
}
43-
return result;
44-
};
45-
});
46-
context.articles = articles.map((name) => {
47-
const markdown = readFileSync(`articles/${name}`, 'utf-8');
48-
const [slug] = name.split('.');
49-
const content = md.render(markdown);
50-
const { date: dateString, ...meta } = md.meta;
51-
const date = new Date(dateString);
52-
const readingTime = ~~(content.split(' ').length / 200);
53-
return { slug, content, date, readingTime, ...meta };
54-
}).sort((a, b) => b.date - a.date);
55-
}
56-
5719
prepare({ page }) {
5820
page.locale = 'pt-BR';
5921
}
@@ -70,21 +32,24 @@ class Application extends Nullstack {
7032
);
7133
}
7234

73-
render({router}) {
35+
renderTrackers() {
7436
return (
75-
<main class="bg-tips-light">
76-
<div>
77-
{
78-
router.url.endsWith('/curso-fullstack-turbo') ? <FacePixelFullStack id="294337825339805" /> : <FacebookPixel id="294337825339805" />
79-
}
80-
81-
{
82-
router.url.endsWith('/curso-react-pro') ? <FacePixelReact id="729313284878557" /> : <FacebookPixel id="294337825339805" />
83-
}
84-
<GoogleAnalytics id="AW-641358523" />
85-
<GoogleAnalytics id="UA-120538403-3" />
86-
</div>
37+
<>
38+
<FacebookPixel id="294337825339805" />
39+
<GoogleAnalytics id="UA-120538403-3" />
40+
<script
41+
async
42+
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7630588299359214"
43+
crossorigin="anonymous"
44+
/>
45+
</>
46+
);
47+
}
8748

49+
render() {
50+
return (
51+
<main class="bg-tips-light">
52+
<Trackers />
8853
<Head />
8954
<Home route="/" />
9055
<Articles route="/artigos" />
@@ -97,12 +62,10 @@ class Application extends Nullstack {
9762
<MiniCourseClasses route="/aulas-do-mini-curso" />
9863
<PageVideoDepo route="/entrevista-com-aluno" />
9964
<Article route="/:slug" />
100-
101-
<span href="/curso-react-pro"> </span>
102-
<span href="/obrigado-por-entrar-no-mini-curso"> </span>
103-
<span href="/aulas-do-mini-curso"> </span>
104-
<span href="/entrevista-com-aluno"> </span>
105-
65+
<span href="/curso-react-pro" />
66+
<span href="/obrigado-por-entrar-no-mini-curso" />
67+
<span href="/aulas-do-mini-curso" />
68+
<span href="/entrevista-com-aluno" />
10669
</main>
10770
);
10871
}

src/course-fullstack-turbo/FacePixelFullStack.njs

-35
This file was deleted.

src/course-react-pro/FacePixelReact.njs

-35
This file was deleted.

0 commit comments

Comments
 (0)