Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

docusaurus-pdf

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docusaurus-pdf - npm Package Compare versions

Comparing version 0.1.2 to 1.0.0

8

bin/index.js

@@ -10,7 +10,7 @@ #!/usr/bin/env node

.name('docusaurus-pdf')
.usage('<initialDocsUrl> [filename] [baseUrl]')
.usage('<initialDocsUrl> [filename]')
.description('Generate PDF from initial docs url')
.arguments('<initialDocsUrl> [filename] [baseUrl]')
.action((initialDocsUrl, filename, baseUrl) => {
generatePdf(initialDocsUrl, filename, baseUrl)
.arguments('<initialDocsUrl> [filename]')
.action((initialDocsUrl, filename) => {
generatePdf(initialDocsUrl, filename)
.then((res) => {

@@ -17,0 +17,0 @@ console.log(chalk.green('Finish generating PDF!'));

@@ -1,1 +0,1 @@

export declare function generatePdf(initialDocsUrl: string, filename?: string, baseUrl?: string): Promise<void>;
export declare function generatePdf(initialDocsUrl: string, filename?: string): Promise<void>;

@@ -53,13 +53,41 @@ "use strict";

};
var safeUrlAppend = function (origin, path, file) {
return origin + (path.length > 0 ? '/' : '') +
path.substring(path.startsWith('/') ? 1 : 0, path.length - (path.endsWith('/') ? 1 : 0)) +
'/' + file;
var getURL = function (origin, filePath) {
return origin + "/" + filePath.substring(filePath.startsWith('/') ? 1 : 0);
};
var getStylesheetPathFromHTML = function (html, origin) {
var regExp = /(?:|<link.*){1}href="(.*styles.*?\.css){1}"/g;
var filePath = "";
try {
filePath = getFirstCapturingGroup(regExp, html);
}
catch (_a) {
throw new Error("The href attribute of the 'styles*.css' file could not be found!");
}
return getURL(origin, filePath);
};
var getScriptPathFromHTML = function (html, origin) {
var regExp = /(?:|<script.*){1}src="(.*styles.*?\.js){1}"/g;
var filePath = "";
try {
filePath = getFirstCapturingGroup(regExp, html);
}
catch (_a) {
throw new Error("The src attribute of the 'styles*.js' file could not be found!");
}
return getURL(origin, filePath);
};
var getFirstCapturingGroup = function (regExp, text) {
var match = regExp.exec(text);
if (match && match[1]) {
return match[1];
}
else {
throw new ReferenceError("No capture group found in the provided text.");
}
};
var generatedPdfBuffers = [];
function generatePdf(initialDocsUrl, filename, baseUrl) {
function generatePdf(initialDocsUrl, filename) {
if (filename === void 0) { filename = "docusaurus.pdf"; }
if (baseUrl === void 0) { baseUrl = ''; }
return __awaiter(this, void 0, void 0, function () {
var browser, page, url, origin, nextPageUrl, e_1, html, pdfBuffer, mergedPdfBuffer;
var browser, page, url, origin, stylePath, scriptPath, nextPageUrl, e_1, html, pdfBuffer, mergedPdfBuffer;
return __generator(this, function (_a) {

@@ -75,2 +103,4 @@ switch (_a.label) {

origin = url.origin;
stylePath = "";
scriptPath = "";
nextPageUrl = initialDocsUrl;

@@ -83,3 +113,10 @@ _a.label = 3;

console.log();
return [4 /*yield*/, page.goto("" + nextPageUrl, { waitUntil: 'networkidle2' })];
return [4 /*yield*/, page.goto("" + nextPageUrl, { waitUntil: 'networkidle2' })
.then(function (resp) { return resp === null || resp === void 0 ? void 0 : resp.text(); })
.then(function (html) {
if (!html)
throw new Error("Page could not be loaded! Did not get any HTML for " + nextPageUrl);
stylePath = getStylesheetPathFromHTML(html, origin);
scriptPath = getScriptPathFromHTML(html, origin);
})];
case 4:

@@ -108,6 +145,6 @@ _a.sent();

_a.sent();
return [4 /*yield*/, page.addStyleTag({ url: safeUrlAppend(origin, baseUrl, 'styles.css') })];
return [4 /*yield*/, page.addStyleTag({ url: stylePath })];
case 11:
_a.sent();
return [4 /*yield*/, page.addScriptTag({ url: safeUrlAppend(origin, baseUrl, 'styles.js') })];
return [4 /*yield*/, page.addScriptTag({ url: scriptPath })];
case 12:

@@ -114,0 +151,0 @@ _a.sent();

{
"name": "docusaurus-pdf",
"version": "0.1.2",
"version": "1.0.0",
"description": "Generate pdf from docusaurus document",

@@ -20,3 +20,4 @@ "main": "lib/index.js",

"devDependencies": {
"@types/puppeteer": "^2.0.1"
"@types/puppeteer": "^2.0.1",
"typescript": "^3.8.3"
},

@@ -23,0 +24,0 @@ "dependencies": {

@@ -13,23 +13,14 @@ ## Introduction

## Usage
### 1. Start your docusaurus project
```sh
yarn start
npx docusaurus-pdf <initialDocsUrl> [filename]
```
### 2. Open new terminal windows
```sh
npx docusaurus-pdf <initialDocsUrl> [filename] [baseUrl]
```
For example
```sh
npx docusaurus-pdf http://localhost:3000/myurl/docs/doc1 hoge.pdf myurl
npx docusaurus-pdf http://localhost:3000/myBaseUrl/docs/doc1 hoge.pdf
```
*NOTE!
- `initialDocsUrl` is required.
- `initialDocsUrl` is required. You can spin up your dev-webserver of docusaurus with `yarn start` or use an already hosted page.
- `filename` is optional (default is `docusaurus.pdf`).
- `baseUrl` is the baseUrl setting from docusaurus.config.js.
It is optional (default is empty string).
You must specify a filename to use a custom baseUrl.

@@ -50,2 +41,2 @@ ## Link of PDF

2. Dark theme PDF cannot be generated correctly now.
2. Dark theme PDF cannot be generated correctly now.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc