Skip to content

Commit

Permalink
make markdown root folder configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
PrajwolAmatya committed Feb 4, 2025
1 parent 9fcb352 commit de12ed9
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 13 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PRESENTATIONS_ROOT=
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ filenameStore.json

markdown/
!tests/unit/testFiles/markdown/

.env
!tests/unit/.env
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ To build the presentation builder run:
pnpm build
```

## Setup Presentations Root Directory

First, copy `.env.example` file and set presentations root directory path at `PRESENTATIONS_ROOT`

```bash
cp .env.example .env
```

## Serve

To serve the presentation builder run:
Expand Down
13 changes: 9 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const utils = require('./utils/utils.js')
const fs = require('fs-extra')
const mustache = require('gulp-mustache')
const rename = require('gulp-rename')
const env = require('dotenv').config()
const config = require('./config')

const ROOT = yargs.argv.root || config.root
Expand All @@ -31,6 +32,7 @@ const FILE = yargs.options({
type: 'string',
},
}).argv.file
const presentationsRoot = env.parsed.PRESENTATIONS_ROOT || 'markdown'

function compileToCSS() {
return gulp
Expand Down Expand Up @@ -74,7 +76,7 @@ function renderIndexHTML(folderName, rawMarkdown) {
md_content: rawMarkdown,
headingData: JSON.stringify(headingData),
presentation_title: fmt[1].metadata.footer,
imagePath: `markdown/${folderName}`,
imagePath: `${presentationsRoot}/${folderName}`,
slideNumber: fmt[1].metadata.slidenumber ?? 'yes',
hideFooter: fmt[1].metadata.footer === undefined || fmt[1].metadata.footer === null,
config: config,
Expand All @@ -86,14 +88,14 @@ function renderIndexHTML(folderName, rawMarkdown) {

function addTOC(folderName, rawMarkdown) {
const metadata = utils.extractFrontmatter(rawMarkdown)
const [title, content] = utils.generateTOC(rawMarkdown, 'markdown/config.yml')
const [title, content] = utils.generateTOC(rawMarkdown, `${presentationsRoot}/config.yml`)
gulp.src('templates/title-content-template.html')
.pipe(
mustache({
title: title,
content: content,
metadata: metadata[1].metadata,
imagePath: `markdown/${folderName}`,
imagePath: `${presentationsRoot}/${folderName}`,
})
)
.pipe(rename('toc-template.html'))
Expand Down Expand Up @@ -169,7 +171,10 @@ gulp.task('serve', () => {
}
storeFilename(FILE)
const folderName = FILE.split('.md')[0]
const rawMarkdown = utils.preProcessMarkdown(`markdown/${folderName}/${FILE}`, 'markdown/config.yml')
const rawMarkdown = utils.preProcessMarkdown(
`${presentationsRoot}/${folderName}/${FILE}`,
`${presentationsRoot}/config.yml`
)
browserifyUtils()
addTOC(folderName, rawMarkdown)
renderIndexHTML(folderName, rawMarkdown)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"devDependencies": {
"browserify": "^17.0.0",
"decktape": "^3.14.0",
"dotenv": "^16.4.7",
"front-matter": "^4.0.2",
"fs-extra": "^11.2.0",
"gulp": "^4.0.2",
Expand Down
24 changes: 20 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/unit/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PRESENTATIONS_ROOT=markdown
12 changes: 7 additions & 5 deletions tests/unit/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const connect = require('gulp-connect')
const utils = require('./testFiles/utils/utils')
const mustache = require('gulp-mustache')
const rename = require('gulp-rename')
const env = require('dotenv').config()
const config = require('./testFiles/config')

const ROOT = yargs.argv.root || config.root
Expand All @@ -15,6 +16,7 @@ const FILE = yargs.options({
type: 'string',
},
}).argv.file
const presentationsRoot = env.parsed.PRESENTATIONS_ROOT

function renderIndexHTML(folderName, rawMarkdown) {
const fmt = utils.extractFrontmatter(rawMarkdown)
Expand All @@ -26,7 +28,7 @@ function renderIndexHTML(folderName, rawMarkdown) {
md_content: rawMarkdown,
headingData: JSON.stringify(headingData),
presentation_title: fmt[1].metadata.footer,
imagePath: `markdown/${folderName}`,
imagePath: `${presentationsRoot}/${folderName}`,
slideNumber: fmt[1].metadata.slidenumber ?? 'yes',
hideFooter: fmt[1].metadata.footer === undefined || fmt[1].metadata.footer === null,
config: config,
Expand All @@ -38,14 +40,14 @@ function renderIndexHTML(folderName, rawMarkdown) {

function addTOC(folderName, rawMarkdown) {
const metadata = utils.extractFrontmatter(rawMarkdown)
const [title, content] = utils.generateTOC(rawMarkdown, 'testFiles/markdown/config.yml')
const [title, content] = utils.generateTOC(rawMarkdown, `testFiles/${presentationsRoot}/config.yml`)
gulp.src('testFiles/templates/title-content-template.html')
.pipe(
mustache({
title: title,
content: content,
metadata: metadata[1].metadata,
imagePath: `markdown/${folderName}`,
imagePath: `${presentationsRoot}/${folderName}`,
})
)
.pipe(rename('toc-template.html'))
Expand All @@ -59,8 +61,8 @@ gulp.task('serve', () => {
}
const folderName = FILE.split('.md')[0]
const rawMarkdown = utils.preProcessMarkdown(
`testFiles/markdown/${folderName}/${FILE}`,
'testFiles/markdown/config.yml'
`testFiles/${presentationsRoot}/${folderName}/${FILE}`,
`testFiles/${presentationsRoot}/config.yml`
)
addTOC(folderName, rawMarkdown)
renderIndexHTML(folderName, rawMarkdown)
Expand Down

0 comments on commit de12ed9

Please sign in to comment.