docuapi icon indicating copy to clipboard operation
docuapi copied to clipboard

How to use theme only for a certain folder?

Open paololazzari opened this issue 1 year ago • 8 comments

If I have content/foo and content/bar, how do I apply the theme only for foo ?

paololazzari avatar Oct 24 '24 09:10 paololazzari

That is a good question. Hugo applies themes as filesystem overlays, so you can have multiple themes on top of each other.

The below is totally untested, but could/should in my head work:

[module]
    [[module.imports]]
        path = "github.com/bep/docuapi/v2"

    [[module.imports.mounts]]
        source = "i18n"
        target = "i18n"

    [[module.imports.mounts]]
        source = "layouts"
        target = "layouts"
    
    [[module.imports.mounts]]
        source = "layouts"
        target = "layouts/foo"

    [[module.imports.mounts]]
        source = "assets"
        target = "assets"

    [[module.imports.mounts]]
        source = "static"
        target = "static"

Note the "double mounting" of layouts.

Also note that I'm not totally sure if the above works, but please let me know if it does.

bep avatar Oct 24 '24 10:10 bep

@bep thanks for the quick reply.

I'm afraid this isn't working for me, the theme is still being loaded for both foo and bar.

paololazzari avatar Oct 24 '24 12:10 paololazzari

@paololazzari - Did you manage to resolve this? I'm assuming you have the same use-case as me, where you want to use one theme for product documentation and docuapi theme for the product's API package?

dannycowlishaw avatar Apr 03 '25 13:04 dannycowlishaw

@dannycowlishaw I couldn't get bep's suggestion to work. I ended up using redocly in a standalone page in layouts/_default/.

paololazzari avatar Apr 03 '25 13:04 paololazzari

Would you mind explaining how you configured redocly exactly? Is it complicated? It might have to be the same workaround I put in place.

dannycowlishaw avatar Apr 03 '25 13:04 dannycowlishaw

@dannycowlishaw sure, it's super easy.

layouts/_default/apireference.html:

<html>
<body>
    <div>
        <redoc 
            spec-url='./openapi.json' 
            >
        </redoc>
        <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> </script>
    </div>
</body>
</html>

content/product/api/api-reference.md:

---
Title: API Reference
layout: apireference
type: page
---

and content/product/api/api-reference/openapi.json is the openapi spec.

paololazzari avatar Apr 03 '25 14:04 paololazzari

Kudos @paololazzari, that's working for me, thank you really appreciate it 😊

dannycowlishaw avatar Apr 03 '25 15:04 dannycowlishaw

@dannycowlishaw you're welcome!

paololazzari avatar Apr 03 '25 15:04 paololazzari