@acto/gatsby-plugin-drive 中文文档教程
gatsby-plugin-drive
下载并缓存一个 Google Drive 文件夹,然后您可以使用 gatsby-source-filesystem
查询该文件夹。 可选择将 Google 文档导出为可用格式。
这项工作仍在进行中。
Installation
yarn add @fs/gatsby-plugin-drive
Usage
为了使用此插件,您需要生成一个 Google 服务帐户并将您的驱动器文件夹与其电子邮件共享。 这是指南。
// In your gatsby-config.js
plugins: [
{
resolve: '@fs/gatsby-plugin-drive',
options: {
folderId: 'GOOGLE_DRIVE_FOLDER_ID',
keyFile: path.resolve(__dirname, 'YOUR_SERVICE_ACCOUNT_KEYFILE.json'),
destination: path.join(__dirname, 'src/content'),
exportGDocs: true,
exportMimeType: 'text/html',
exportMiddleware: someFunction
}
}
]
如果启用 exportGDocs
选项,则文件夹中的所有 Google 文档都将使用 exportMimeType
选项中设置的 MIME 类型导出。 您可以在此处查看可用的 Google 文档导出 MIME 类型列表。 如果禁用 exportGDocs
选项,文件夹中的所有 Google 文档都将被忽略。
exportMiddleware
选项是可选的。 如果设置,插件将通过该函数运行每个 Google 文档,然后再将其写入磁盘。 一个用例可能是清理或操作 Google Drive API 返回的 HTML。
预期的函数签名是 Buffer -> 缓冲区。
您的驱动器文件夹将在每次构建时下载所有文件,除非文件已存在或已缓存。 要再次下载所有文件,请设置一个 npm clean 脚本,例如:
"clean": "rimraf src/content",
Author
- Fabian Schultz (@fschultz_) - Stink Studios
- Elias Jørgensen (@_eliasjorgensen)
gatsby-plugin-drive
Downloads and caches a Google Drive folder that you can then query with gatsby-source-filesystem
. Optionally exports Google Docs to a usable format.
This is still a work in progress.
Installation
yarn add @fs/gatsby-plugin-drive
Usage
In order to use this plugin, you'll need to generate a Google Service Account and share your drive folder with its email. Here's a guide.
// In your gatsby-config.js
plugins: [
{
resolve: '@fs/gatsby-plugin-drive',
options: {
folderId: 'GOOGLE_DRIVE_FOLDER_ID',
keyFile: path.resolve(__dirname, 'YOUR_SERVICE_ACCOUNT_KEYFILE.json'),
destination: path.join(__dirname, 'src/content'),
exportGDocs: true,
exportMimeType: 'text/html',
exportMiddleware: someFunction
}
}
]
If the exportGDocs
option is enabled, all Google Docs in the folder will be exported with the MIME type set in the exportMimeType
option. You can see a list of available Google Docs export MIME types here. If the exportGDocs
option is disabled, all Google Docs in the folder will be ignored.
The exportMiddleware
option is optional. If set, the plugin will run each Google Doc through the function, before it writes it to disk. A usecase for this, could be cleaning up, or manipulating, the HTML that the Google Drive API returns.
The expected function signature is Buffer -> Buffer
.
Your drive folder will download all files everytime it builds, except when a file already exists or is cached. To download all files again, set up an npm clean script like:
"clean": "rimraf src/content",
Author
- Fabian Schultz (@fschultz_) - Stink Studios
- Elias Jørgensen (@_eliasjorgensen)