Skip to content
This repository was archived by the owner on Apr 15, 2021. It is now read-only.

Commit f730b75

Browse files
committed
Add logic to populate placeholders in markdown
1 parent 70f753f commit f730b75

File tree

11 files changed

+52
-18
lines changed

11 files changed

+52
-18
lines changed

components/Header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Logo from './Logo'
2222
import Router from 'next/router'
2323
import clsx from 'clsx'
2424
import HeaderCollapseMenu from './HeaderCollapseMenu'
25-
import { APP_URL, FORUM_URL, STATUS_URL } from '../consts'
25+
import { APP_URL, FORUM_URL, STATUS_URL } from '../constants'
2626

2727
const useStyles = makeStyles(theme => ({
2828
appBar: {

components/HeaderCollapseMenu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Link from 'next/link'
66
import { MoreVert } from '@material-ui/icons'
77
import { makeStyles } from '@material-ui/core/styles'
88
import { Hidden } from '@material-ui/core'
9-
import { APP_URL, FORUM_URL, STATUS_URL, HELP_URL } from '../consts'
9+
import { APP_URL, FORUM_URL, STATUS_URL, HELP_URL } from '../constants'
1010

1111
const useStyles = makeStyles(theme => ({
1212
root: {

components/utils/markdownUtils.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as constants from '../../constants'
2+
3+
function replaceMatch(content, match) {
4+
const [template, variable] = match
5+
6+
return (
7+
content.substr(0, match.index) +
8+
constants[variable] +
9+
content.substr(match.index + template.length)
10+
)
11+
}
12+
13+
/**
14+
* Populates the markdown template with replacement values for all
15+
* constant placeholders with pattern: {{ VARIABLE_NAME }}
16+
*
17+
* @param {String} content
18+
* @returns {String}
19+
*/
20+
export function populatePlaceholders(content) {
21+
const matcher = /{{\s*(\w+)\s*}}/g
22+
let result
23+
24+
while ((result = matcher.exec(content)) !== null) {
25+
const [, variable] = result
26+
27+
if (constants[variable]) {
28+
content = replaceMatch(content, result)
29+
}
30+
}
31+
32+
return content
33+
}
File renamed without changes.

guides/angular.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Angular
22

3-
This guide shows you how to deploy an Angular application on the Moovweb XDN:
3+
This guide shows you how to deploy an Angular application on {{ PRODUCT_NAME }}:
44

55
## Example SSR Site
66

@@ -11,11 +11,11 @@ This Angular example app uses server-side rendering and prefetching to provide l
1111

1212
## Install Node.js and npm
1313

14-
**XDN only supports Node.js version 12.x**
14+
**{{ PRODUCT_NAME }} only supports Node.js version 12.x**
1515

1616
If you do not have Node.js installed on your system, download and install it from the official [Node.js v12.x downloads](https://nodejs.org/dist/latest-v12.x/) page. Select the download that matches your operating system and run the installer. Note that the installer for Node.js will also install npm.
1717

18-
_Note that while you can use any version of Node.js >= 12 locally, your app will run in Node 12 when deployed to the XDN cloud. Therefore we highly suggest using Node 12 for all development._
18+
_Note that while you can use any version of Node.js >= 12 locally, your app will run in Node 12 when deployed to the {{ PRODUCT_NAME }} cloud. Therefore we highly suggest using Node 12 for all development._
1919

2020
## Getting Started
2121

@@ -32,7 +32,7 @@ You should now have a working starter app. Run `ng serve` to see the application
3232

3333
#### 2. Add SSR
3434

35-
To deploy your Angular application on the Moovweb XDN it needs to support server-side rendering (SSR). To add SSR support, run:
35+
To deploy your Angular application on {{ PRODUCT_NAME }} it needs to support server-side rendering (SSR). To add SSR support, run:
3636

3737
```bash
3838
ng add @nguniversal/express-engine
@@ -49,15 +49,15 @@ The previous command created:
4949

5050
You can now run `npm run build:ssr && npm run serve:ssr` to access your server-side rendered app at `localhost:4000`.
5151

52-
To prepare your Angular application for deployment on the Moovweb XDN:
52+
To prepare your Angular application for deployment on {{ PRODUCT_NAME }}:
5353

54-
#### 1. Install the XDN CLI globally:
54+
#### 1. Install {{ PRODUCT_NAME }} CLI globally:
5555

5656
```bash
5757
npm install -g @xdn/cli
5858
```
5959

60-
#### 2. Run the following in the root folder of your project. This will configure your project for the XDN.
60+
#### 2. Run the following in the root folder of your project. This will configure your project for {{ PRODUCT_NAME }}.
6161

6262
```bash
6363
xdn init
@@ -68,7 +68,7 @@ This will automatically add all of the required dependencies and files to your p
6868
- The `@xdn/core` package
6969
- The `@xdn/angular` package
7070
- The `@xdn/cli` package
71-
- `xdn.config.js`- Contains various configuration options for the XDN.
71+
- `xdn.config.js`- Contains various configuration options for {{ PRODUCT_NAME }}.
7272
- `routes.js` - A default routes file that sends all requests to the Angular Universal server. Update this file to add caching or proxy some URLs to a different origin.
7373

7474
#### 3. Use the right angular project
@@ -137,7 +137,7 @@ ANGULAR_PROJECT=my-project xdn run
137137

138138
## Deploying
139139

140-
Deploying requires an account on the Moovweb XDN. [Sign up here for free.](https://moovweb.app/signup) Once you have an account, you can deploy to the Moovweb XDN by running the following in the root folder of your project:
140+
Deploying requires an account on {{ PRODUCT_NAME }}. [Sign up here for free.](https://moovweb.app/signup) Once you have an account, you can deploy to {{ PRODUCT_NAME }} by running the following in the root folder of your project:
141141

142142
```bash
143143
xdn deploy

pages/_document.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import Document, { Html, Head, Main, NextScript } from 'next/document'
33
import { ServerStyleSheets } from '@material-ui/core/styles'
44
import theme from '../components/theme'
5-
import { DOCS_DOMAIN } from '../consts'
5+
import { DOCS_DOMAIN } from '../constants'
66

77
class MyDocument extends Document {
88
render() {

pages/api/guides.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fetch from 'isomorphic-fetch'
2-
import { DOCS_PAGES_REPO_URL } from '../../consts'
2+
import { DOCS_PAGES_REPO_URL } from '../../constants'
33

44
export default async function guides(req, res) {
55
const { version } = req.query

pages/api/guides/[guide].js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fetch from 'isomorphic-fetch'
2-
import { DOCS_PAGES_REPO_URL } from '../../../consts'
2+
import { DOCS_PAGES_REPO_URL } from '../../../constants'
33

44
export default async function guide(req, res) {
55
let { version, guide } = req.query

pages/api/modules/[version].js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fetch from 'isomorphic-fetch'
2-
import { DOCS_PAGES_REPO_URL } from '../../../consts'
2+
import { DOCS_PAGES_REPO_URL } from '../../../constants'
33

44
export default async function version(req, res) {
55
const { version } = req.query

pages/guides/[...guide].js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import getBaseUrl from '../../components/utils/getBaseUrl'
99
import ApiLink from '../../components/ApiLink'
1010
import { Typography } from '@material-ui/core'
1111
import { useTheme } from '@material-ui/styles'
12-
import { PRODUCT_NAME } from '../../consts'
12+
import { PRODUCT_NAME } from '../../constants'
13+
import { populatePlaceholders } from '../../components/utils/markdownUtils'
1314

1415
export default function Guide({ notFound, markdown, navData, guide }) {
1516
if (notFound) {
@@ -74,7 +75,7 @@ Guide.getInitialProps = async function({ req, query, version }) {
7475
])
7576

7677
return {
77-
markdown: content,
78+
markdown: populatePlaceholders(content),
7879
navData,
7980
guide,
8081
}

0 commit comments

Comments
 (0)