Skip to content

Commit

Permalink
feat: added new flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Guille committed Feb 21, 2024
1 parent 0c75d31 commit 1467428
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import NotionExporter from "notion-exporter"
const tokenV2 = ...
const fileToken = ...
const blockId = "3af0a1e347dd40c5ba0a2c91e234b2a5"
const nofiles = false // download also PDF and image files
const allfiles = false // don't download PDF and image files
const recursive = false // download only blockId

await new NotionExporter(tokenV2, fileToken, nofiles, recursive).getMdString(blockId)
Expand Down Expand Up @@ -70,11 +70,6 @@ exporter.getZipUrl(blockId: string): Promise<string>
exporter.getZip(url: string): Promise<AdmZip>
```

Also chance to unzip all the exported files in the zip in a folder.
```ts
exporter.getMdFiles(blockId: string, folder: string): Promise<void>
```

## Needed Cookies

To export anything from Notion, one needs to authenticate oneself with some
Expand Down
10 changes: 0 additions & 10 deletions src/NotionExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,4 @@ export class NotionExporter {
*/
getMdString = (idOrUrl: string): Promise<string> =>
this.getFileString(idOrUrl, (e) => e.name.endsWith(".md"))

/**
* Downloads ane extracts into a folder all files in the exported zip file.
* @param idOrUrl BlockId or URL of the page/block/DB to export
* @param folder The folder where the files are going to be unzipped
*/
getMdFiles = async (idOrUrl: string, folder: string): Promise<void> => {
const zip = await this.getZipUrl(idOrUrl).then(this.getZip)
zip.extractAllTo(folder)
}
}
2 changes: 1 addition & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const askToken = (tokenName: string): Promise<string> => {
const envOrAskToken = async (tokenName: string) =>
process.env[tokenName] || (await askToken(tokenName))

const action = async (blockId: string, fileType: string, noFiles: boolean, recursive: boolean = false) => {
const action = async (blockId: string, fileType: string, noFiles: boolean, recursive: boolean) => {

Check failure on line 28 in src/action.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 16.x and ubuntu-latest

Replace `blockId:·string,·fileType:·string,·noFiles:·boolean,·recursive:·boolean` with `⏎··blockId:·string,⏎··fileType:·string,⏎··noFiles:·boolean,⏎··recursive:·boolean⏎`
if (!isFileType(fileType)) {
console.log(`File type (-t, --type) has to be one of: ${FileType}`)
process.exit(1)
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const cli = (args: string[]) => {
© ${pkg.author}, 2022.`
)
.option('-r, --recursive', 'Export also subpages (default: false)')
.option('-n, --no-files', 'Don\'t export image and pdf files, only content (default: all content is exported)')
.option('-r, --recursive', 'Export children subpages', false)
.option('-a, --all-files', 'Export image and pdf files, not only content', false)
.option("-t, --type", `File type to be exported: ${FileType}`, "md")
// .option("-o, --output", "Output path of the exported file, stdin if empty")
.example(
Expand All @@ -31,6 +31,6 @@ export const cli = (args: string[]) => {
.example("83715d7703ee4b8699b5e659a4712dd8 -t md")
.example("3af0a1e347dd40c5ba0a2c91e234b2a5 -t csv > list.csv")
// .example("83715d7703ee4b8699b5e659a4712dd8 -t md -o blog.md")
.action((blockId, opts) => action(blockId, opts.type, opts.n && true, opts.recursive))
.action((blockId, opts) => action(blockId, opts.type, opts.a, opts.recursive))
.parse(args)
}

0 comments on commit 1467428

Please sign in to comment.