Skip to content

Commit 2b22872

Browse files
committed
Gibook migration guide
1 parent e2c4721 commit 2b22872

File tree

2 files changed

+211
-7
lines changed

2 files changed

+211
-7
lines changed

README_Migrate_Gitbook.mdx

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/gitbook.mdx

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
---
2+
sidebar_position: 2.5
3+
sidebar_label: Gitbook Migration
4+
slug: /gitbook-migration
5+
description: How to migrate from GitBook to Docusaurus
6+
---
7+
8+
# Migrate GitBook to Docusaurus
9+
10+
This page explains how to migrate from GitBook to Docusaurus. For newcomers, Docusaurus is a static-site generator. It builds a single-page application with fast client-side navigation, leveraging the full power of React to make your site interactive. It provides out-of-the-box documentation features but can be used to create any kind of site (personal website, product, blog, marketing landing pages, etc).
11+
12+
## Key Features
13+
14+
Docusaurus is built with high attention to the developer and contributor experience.
15+
16+
⚛️ Built with 💚 and React:
17+
18+
Extend and customize with React
19+
Gain full control of your site's browsing experience by providing your own React components
20+
21+
Pluggable:
22+
23+
Bootstrap your site with a basic template, then use advanced features and plugins
24+
Open source your plugins to share with the community
25+
26+
✂️ Developer experience:
27+
28+
Start writing your docs right now
29+
Universal configuration entry point to make it more maintainable by contributors
30+
Hot reloading with lightning-fast incremental build on changes
31+
Route-based code and data splitting
32+
Publish to GitHub Pages, Netlify, Vercel, and other deployment services with ease
33+
Our shared goal—to help your users quickly find what they need and understand your products better. We share our best practices to help you build your docs site right and well.
34+
35+
🎯 SEO friendly:
36+
37+
HTML files are statically generated for every possible path.
38+
Page-specific SEO to help your users land on your official docs directly relating their problems at hand.
39+
40+
📝 Powered by MDX:
41+
42+
Write interactive components via JSX and React embedded in Markdown.
43+
Share your code in live editors to get your users to love your products on the spot.
44+
45+
🔍 Search:
46+
Your full site is searchable.
47+
48+
💾 Document Versioning:
49+
50+
Helps you keep documentation in sync with project releases.
51+
52+
🌍 Internationalization (i18n):
53+
Translate your site in multiple locales.
54+
55+
Docusaurus 2 is born to be compassionately accessible to all your users, and lightning-fast.
56+
57+
⚡️ Lightning-fast.
58+
59+
Docusaurus 2 follows the PRPL Pattern that makes sure your content loads blazing fast.
60+
61+
🦖 Accessible.
62+
Attention to accessibility, making your site equally accessible to all users.
63+
64+
# Migration Steps
65+
66+
## step 1 - Generate a new Docusaurus site
67+
68+
Generate a new Docusaurus site using the classic template.
69+
70+
The classic template will automatically be added to your project after you run the command:
71+
72+
```bash
73+
npm init docusaurus@latest my-website classic
74+
```
75+
76+
You can type this command into Command Prompt, Powershell, Terminal, or any other integrated terminal of your code editor.
77+
78+
The command also installs all necessary dependencies you need to run Docusaurus.
79+
80+
## step 2 - Start your site
81+
82+
Run the development server:
83+
84+
```bash
85+
cd my-website
86+
npm run start
87+
```
88+
89+
The cd command changes the directory you're working with. In order to work with your newly created Docusaurus site, you'll need to navigate the terminal there.
90+
91+
The npm run start command builds your website locally and serves it through a development server, ready for you to view at http://localhost:3000/.
92+
93+
Open docs/intro.md (this page) and edit some lines: the site reloads automatically and displays your changes.
94+
95+
## step 3 - copy documentation content from GitBook to docusaurus
96+
97+
1. First Navigate to docs folder and delee the generated tutorial docs from docusaurus ,
98+
2. Navigate to gibook project folder copy all contents except .git and .gibook and move them to the docusaurus project under docs/
99+
3. Convert all doc files from md to mdx extension
100+
4. you will get this error "DocNavbarItem: couldn't find any doc with id "intro" in version current". Available doc ids are: ..""
101+
this is because the navbar is set to the previous deleted tutorial doc files in step 1.
102+
103+
### Solution
104+
105+
go to docusaurus.config.js at the root of the project Edit themeConfig:navbar:items[0] change docId docId: "app-generator",
106+
to one of the available doc ids from the error above
107+
108+
5. Build the project run:
109+
110+
```bash
111+
npm run build
112+
```
113+
114+
# SSR
115+
116+
1. Create a ssr folder on the root of docusaurus project
117+
118+
2. Create file index.js inside ssr folder and add below code
119+
120+
```jsx title="/ssr/index.js"
121+
const express = require("express");
122+
const fs = require("fs");
123+
const path = require("path");
124+
125+
// create express application
126+
const app = express();
127+
128+
const distFolder = path.join(process.cwd(), "../build");
129+
130+
app.set("view engine", "html");
131+
app.set("views", distFolder);
132+
133+
// app.get(
134+
// "/appSeed//.(js|css|map|ico|svg|png|jpg|jpeg)$/",
135+
// express.static(distFolder, {
136+
// maxAge: "1y",
137+
// })
138+
// );
139+
// serve static assets
140+
app.get(/\.(js|css|map|ico|svg|png|jpg|jpeg|woff2)$/, express.static(path.resolve(__dirname, "../build")));
141+
142+
// for any other requests, send `index.html` as a response
143+
144+
app.get("/sitemap.xml", (req, res) => {
145+
let indexHTML = fs.readFileSync(path.resolve(__dirname, "../build/" + req.originalUrl), {
146+
encoding: "utf8",
147+
});
148+
149+
// set header and status
150+
res.contentType("text/xml");
151+
res.status(200);
152+
153+
return res.send(indexHTML);
154+
});
155+
app.get("/opensearch.xml", (req, res) => {
156+
let indexHTML = fs.readFileSync(path.resolve(__dirname, "../build/" + req.originalUrl), {
157+
encoding: "utf8",
158+
});
159+
160+
// set header and status
161+
res.contentType("text/xml");
162+
res.status(200);
163+
164+
return res.send(indexHTML);
165+
});
166+
app.get("/favicon.ico", (req, res) => {
167+
let indexHTML = fs.readFileSync(path.resolve(__dirname, "../build/" + req.originalUrl), {
168+
encoding: "utf8",
169+
});
170+
171+
// set header and status
172+
res.contentType("png");
173+
res.status(200);
174+
175+
return res.send(indexHTML);
176+
});
177+
178+
app.use("*", (req, res) => {
179+
if (req.originalUrl.includes("assets")) return express.static(path.resolve(__dirname, "../build/" + req.originalUrl));
180+
console.log("url", req.originalUrl);
181+
// console.log("method", req.method);
182+
let indexHTML;
183+
// read `index.html` file
184+
if (req.originalUrl == "/") {
185+
indexHTML = fs.readFileSync(path.resolve(__dirname, "../build/index.html"), {
186+
encoding: "utf8",
187+
});
188+
} else {
189+
indexHTML = fs.readFileSync(path.resolve(__dirname, "../build/" + req.originalUrl + "/index.html"), {
190+
encoding: "utf8",
191+
});
192+
}
193+
194+
// set header and status
195+
res.contentType("text/html");
196+
res.status(200);
197+
198+
return res.send(indexHTML);
199+
});
200+
201+
// run express server on port 9000
202+
app.listen("9000", () => {
203+
console.log("Express server started at http://localhost:9000");
204+
});
205+
```
206+
207+
3. run the ssr version of the app after building project
208+
209+
```bash
210+
node ssr/index.js
211+
```

0 commit comments

Comments
 (0)