Skip to content

Commit a366c56

Browse files
📝 Update README with recipe, CLI
1 parent 4cd0435 commit a366c56

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

README.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,24 @@ Install the package from [npm](https://www.npmjs.com/package/docs-markdown):
2525
npm install docs-markdown
2626
```
2727

28-
Import and use:
28+
### API
29+
30+
The `fetchGoogleDocsFiles` helper can download a document from Google Docs and save it as a markdown file:
31+
32+
```ts
33+
import { fetchGoogleDocsFiles } from "docs-markdown";
34+
35+
// Google Docs document ID
36+
await fetchGoogleDocsFiles(["1UEUrJ98RXu9BNcFj3pMgiUALQpjIb8Y-gNu-YhlYvFQ"]);
37+
38+
// Google Docs document ID and file name
39+
await fetchGoogleDocsFiles(["1UEUrJ98RXu9BNcFj3pMgiUALQpjIb8Y-gNu-YhlYvFQ:filename.md"]);
40+
41+
// Multiple Google Docs documents (comma-separated string)
42+
await fetchGoogleDocsFiles(["documentId1", "documentId2", "documentId3"]);
43+
```
44+
45+
You can also use the `googleDocsToMarkdown` function to manually convert documents:
2946

3047
```ts
3148
import { googleDocsToMarkdown } from "docs-markdown";
@@ -43,6 +60,35 @@ const markdown = googleDocsToMarkdown(file.data);
4360
writeFileSync("file.md", markdown);
4461
```
4562

63+
### CLI
64+
65+
Fetch files and save them as markdown:
66+
67+
```bash
68+
# Google Docs document ID
69+
docs-markdown fetch "1UEUrJ98RXu9BNcFj3pMgiUALQpjIb8Y-gNu-YhlYvFQ"
70+
71+
# Google Docs document ID with file name
72+
docs-markdown fetch "1UEUrJ98RXu9BNcFj3pMgiUALQpjIb8Y-gNu-YhlYvFQ:filename.md"
73+
74+
# Multiple Google Docs documents
75+
docs-markdown fetch "documentId1, documentId2, documentId3"
76+
77+
# Convert a JSON document to markdown
78+
docs-markdown convert "path/to/file.json"
79+
```
80+
81+
### Authentication
82+
83+
The following environment variables are required to fetch files from Google Docs. They are not required when converting JSON documents to markdown:
84+
85+
- `GOOGLE_DOCS_CLIENT_ID`
86+
- `GOOGLE_DOCS_CLIENT_SECRET`
87+
- `GOOGLE_DOCS_ACCESS`
88+
- `GOOGLE_DOCS_REFRESH`
89+
90+
To learn how to create a client ID and secret, read the article [Using OAuth 2.0 to Access Google APIs](https://developers.google.com/identity/protocols/oauth2). Once you've created them, create an access token and a refresh token, use the [OAuth 2.0 Playground](https://developers.google.com/oauthplayground/) with your client ID and secret.
91+
4692
## ⭐️ Features
4793

4894
- [x] Paragraphs
@@ -54,6 +100,44 @@ writeFileSync("file.md", markdown);
54100
- [ ] Tables
55101
- [ ] Header, footer
56102

103+
## 🍳 Recipes
104+
105+
### GitHub Actions + Google Docs CI
106+
107+
If you want to sync your Google Docs documents as markdown files to a GitHub repository, you can use this GitHub Actions workflow that runs every day, fetches your documents, and commit them to your repo. Make sure you have all the required environment variables stored as GitHub Secrets:
108+
109+
```yml
110+
name: Google Docs
111+
on:
112+
schedule:
113+
- cron: "0 0 * * *"
114+
jobs:
115+
release:
116+
name: Fetch Google Docs
117+
runs-on: ubuntu-18.04
118+
steps:
119+
- name: Checkout
120+
uses: actions/checkout@v2
121+
- name: Setup Node.js
122+
uses: actions/setup-node@v1
123+
with:
124+
node-version: 12
125+
- name: Download files
126+
run: npx docs-markdown fetch "1UEUrJ98RXu9BNcFj3pMgiUALQpjIb8Y-gNu-YhlYvFQ"
127+
env:
128+
GOOGLE_DOCS_ACCESS: ${{ secrets.GOOGLE_DOCS_ACCESS }}
129+
GOOGLE_DOCS_REFRESH: ${{ secrets.GOOGLE_DOCS_REFRESH }}
130+
GOOGLE_DOCS_CLIENT_ID: ${{ secrets.GOOGLE_DOCS_CLIENT_ID }}
131+
GOOGLE_DOCS_CLIENT_SECRET: ${{ secrets.GOOGLE_DOCS_CLIENT_SECRET }}
132+
- name: Commit new data
133+
uses: stefanzweifel/git-auto-commit-action@v4.1.1
134+
with:
135+
commit_message: "Update Google Docs file"
136+
commit_user_name: GitHub Actions
137+
commit_user_email: actions@github.com
138+
commit_author: GitHub Actions <actions@github.com>
139+
```
140+
57141
## 👩‍💻 Development
58142
59143
Build TypeScript:

0 commit comments

Comments
 (0)