rdilweb / docusaurus-plugin-remote-content

A Docusaurus plugin to download content from remote sources when it is needed.
MIT License
94 stars 12 forks source link

Directory download support #30

Closed thomasheartman closed 2 years ago

thomasheartman commented 2 years ago

Hi! I was tipped about this plugin from the Docusaurus Discord and it looks like an amazing fit for what I was looking for; thank you for creating it 😄

I was wondering whether there's any support for either downloading directories (including subdirectories) or downloading all files in a directory / at a url, or if that's planned at all? Judging from the readme, it doesn't look like it, but I thought I'd ask anyway.

Regardless of whether this is supported (or planned), the plugin still seems incredibly useful for my purposes; I just want to know what the limits are, so I can plan with them in mind. Thanks again!

RDIL commented 2 years ago

So yeah, you can, but it requires a bit of scripting. The plugin is meant to be platform-independent so you will need to manually index the directories. What you could do is something like this:

// in plugin options
async documents() {
    const theDocuments = await makeSomeApiRequests()

    return theDocuments
}
thomasheartman commented 2 years ago

Ah, right! So if I understand you correctly, you just use that in place of the usual property? So, using the example from the readme, I'd get something like this:

module.exports = {
    // ...
    plugins: [
        [
            "docusaurus-plugin-remote-content",
            {
                // options here
                name: "some-content", // used by CLI, must be path safe
                sourceBaseUrl: "https://my-site.com/content/", // the base url for the markdown (gets prepended to all of the documents when fetching)
                outDir: "docs", // the base directory to output to.
                async documents() {
                    const theDocuments = await makeSomeApiRequests()

                    return theDocuments
                }
            },
        ],
    ],
}

And the theDocuments is basically just the path to all the documents from the sourceBaseUrl, right?

Thank you!

RDIL commented 2 years ago

Yeah, an array of paths relative to the base URL.

thomasheartman commented 2 years ago

Thanks! That sounds like what I need 😄 I'll go ahead and close this issue, then.