Skip to content

Commit

Permalink
export pdf cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
milesstoetzner committed Jun 26, 2023
1 parent ecf76f4 commit 33fe41b
Show file tree
Hide file tree
Showing 6 changed files with 479 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ yarn-error.log
.DS_STORE

build-docs
dist-docs

# xopera
*.opera
Expand Down
93 changes: 93 additions & 0 deletions docs/cmds/export/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import * as files from '#files'
import {sleep} from '#utils'
import dayjs from '#utils/day'
import console from 'console'
import * as path from 'path'
import puppeteer, {Browser, PDFOptions} from 'puppeteer'

type Job = {
url: string
name: string
}

const jobs: Job[] = [
{
url: 'https://vintner.opentosca.org/variability4tosca/specification',
name: 'variability4tosca-01-motivation',
},
{
url: 'https://vintner.opentosca.org/variability4tosca/specification',
name: 'variability4tosca-02-specification',
},
{
url: 'https://vintner.opentosca.org/variability4tosca/testing',
name: 'variability4tosca-03-testing',
},
{
url: 'https://vintner.opentosca.org/variability4tosca/feature-ide',
name: 'variability4tosca-04-feature-ide',
},
{
url: 'https://vintner.opentosca.org/queries4tosca/getting-started',
name: 'queries4tosca-01-getting-started',
},
{
url: 'https://vintner.opentosca.org/queries4tosca/specification',
name: 'queries4tosca-02-specification',
},
{
url: 'https://vintner.opentosca.org/sofdcar/profile',
name: 'tosca-sofdcar-profile-01-profile',
},
{
url: 'https://vintner.opentosca.org/sofdcar/guides/zone',
name: 'tosca-sofdcar-profile-02-guides-zone',
},
{
url: 'https://vintner.opentosca.org/sofdcar/guides/location',
name: 'tosca-sofdcar-profile-03-guides-location',
},
]

let browser: Browser
const dist = path.join(__dirname, '..', '..', '..', 'dist-docs')

async function run(job: Job) {
console.log('Processing', job.url)

const page = await browser.newPage()

await page.emulateMediaType('screen')
await page.setViewport({width: 1920, height: 1080})

await page.goto(job.url, {waitUntil: 'networkidle2'})

await sleep(1000)

await page.addStyleTag({
content: `
.md-header, .md-footer {
display: none !important;
}`,
})

const config: PDFOptions = {
path: path.join(dist, job.name + '-' + dayjs().format('YYYY-MM-DD') + '.pdf'),
format: 'A4',
scale: 0.7,
preferCSSPageSize: true,
}

await page.pdf(config)
}

async function main() {
files.removeDirectory(dist)
files.createDirectory(dist)

browser = await puppeteer.launch({headless: 'new'})
await Promise.all(jobs.map(run))
await browser.close()
}

main()
4 changes: 4 additions & 0 deletions docs/docs/assets/stylesheets/print.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@page {
size: A4;
margin: 8mm;
}
1 change: 1 addition & 0 deletions docs/mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extra_css:
- assets/stylesheets/typeset.css
- assets/stylesheets/asciinema-player.css
- assets/stylesheets/enumerate-headers.css
- assets/stylesheets/print.css

extra_javascript:
- assets/javascripts/tablesort.min.js
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"pkg": "^5.8.1",
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.8.7",
"puppeteer": "^20.7.3",
"semver": "^7.5.2",
"sync-directory": "^6.0.4",
"ts-node": "^10.9.1",
Expand Down Expand Up @@ -124,6 +125,7 @@
"docs:record": "yarn docs:record:home && yarn docs:record:getting-started",
"docs:record:home": "cd docs/cmds/casts && bash record.sh home",
"docs:record:getting-started": "cd docs/cmds/casts && bash record.sh getting-started",
"docs:export": "bash docs/cmds/command.sh export",
"examples:xopera": "bash examples/xopera-motivation/demo.sh",
"examples:unfurl": "bash examples/unfurl-motivation/demo.sh",
"licenses:check": "license-checker --production --summary --onlyAllow \"MIT;Apache-2.0;Python-2.0;BSD-2-Clause;BSD-3-Clause;ISC;CC-BY-3.0;CC0-1.0;PSF;0BSD;BlueOak-1.0.0\" --excludePackages [email protected]",
Expand Down
Loading

0 comments on commit 33fe41b

Please sign in to comment.