Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make docsy a go module (with its own submodules) #520

Closed
wants to merge 2 commits into from

Conversation

deining
Copy link
Collaborator

@deining deining commented Apr 16, 2021

Making docsy a go module was discussed in issue 456 already. I'm citing from there:

I think we looked at making Docsy into a module
(with its own modules - it currently has Git submodules)
and it would have required a fair bit of refactoring, (...).
It's definitely something to revisit though.

I worked myself into hugo modules recently and ended up with this PR which turns docsy into a module —without the need of any refactoring of the existing codebase. The only change needed is to add a module section (with several imports and mounts) to config.toml.

With a new hugo site set up and a fresh copy of the docsy theme cloned to the themes folder, let's compare the proposed modules approach with the current submodules approach:

Resolving dependencies with Submodules (current HEAD)

$ # inside /path/to/mysite/themes
$ time git submodule update --init --recursive
Submodule 'assets/vendor/Font-Awesome' (https://github.com/FortAwesome/Font-Awesome.git) registered for path 'assets/vendor/Font-Awesome'
Submodule 'assets/vendor/bootstrap' (https://github.com/twbs/bootstrap.git) registered for path 'assets/vendor/bootstrap'
Cloning into '/path/to/docsy/assets/vendor/Font-Awesome'...
Cloning into '/path/to/docsy/assets/vendor/bootstrap'...
Submodule path 'assets/vendor/Font-Awesome': checked out 'fcec2d1b01ff069ac10500ac42e4478d20d21f4c'
Submodule path 'assets/vendor/bootstrap': checked out '6ffb0b48e455430f8a5359ed689ad64c1143fac2'

real    0m29.895s

Pulling in dependencies with Docsy as Hugo module (this PR applied)

$ # inside /path/to/mysite/themes
time hugo mod vendor --ignoreVendorPaths **
hugo: downloading modules …
hugo: collected modules in 6274 ms

real    0m7.421s

As you can see, the process is more than 4 times faster now.

Let's compare downloaded file sizes:

With Submodules (current HEAD)

$ # inside /path/to/mysite/_vendor
$ du . -h
12K     ./github.com/deining/hugo-mod-font-awesome-scss
12K     ./github.com/deining
254K    ./github.com/FortAwesome/Font-Awesome/scss
254K    ./github.com/FortAwesome/Font-Awesome
254K    ./github.com/FortAwesome
12K     ./github.com/gohugoio/hugo-mod-bootstrap-scss-v4/assets/scss/bootstrap/_vendor
12K     ./github.com/gohugoio/hugo-mod-bootstrap-scss-v4/assets/scss/bootstrap
12K     ./github.com/gohugoio/hugo-mod-bootstrap-scss-v4/assets/scss
12K     ./github.com/gohugoio/hugo-mod-bootstrap-scss-v4/assets
28K     ./github.com/gohugoio/hugo-mod-bootstrap-scss-v4
28K     ./github.com/gohugoio
79K     ./github.com/twbs/bootstrap/scss/mixins
37K     ./github.com/twbs/bootstrap/scss/utilities
367K    ./github.com/twbs/bootstrap/scss
379K    ./github.com/twbs/bootstrap
379K    ./github.com/twbs
673K    ./github.com
674K    .

With Docsy as Hugo module (this PR applied)

$ # inside /path/to/mysite/themes/docsy/assets/vendor
$ du . -hs
56M     .

As you can see, the download size is drastically reduced now.

Requirements for using Hugo modules (this PR applied)

  • hugo extended (as ususal)
  • go (I used latest version 1.16.3)

Having to deal with submodules when setup a new docsy theme doesn't account for a nice first time user experience IMHO. I even tend to say it scares users away from using dosy. I think this PR proposes a pretty neat alternative which is far superior to the existing solution IMHO, and I would like to put it up for discussion now.

I'm willing to follow up on currrent work and rework and/or extend the current documentation. However, prior to that, there are a few issues which should be clarified, like:

  • Can my PR be accepted and merged?
  • If so, will the modules approach replace the current submodules approach or do we want to have both side by side?
  • (maybe a bit provocative): do we need submodules/hugo modules for docsy's dependencies at all? Why don't we simply check in the scss files needed? With hugo modules in place (this PR applied) it should be fairly easy for the maintainers to update the exsiting scss files once a new version of bootstrap/font awesome is released.
  • ...

The discussion is open, looking forward to your input.

One last note: this blog post explains how to add a theme to an existing site using modules.

@LisaFC
Copy link
Collaborator

LisaFC commented Apr 19, 2021

This is super interesting and would definitely potentially make dependencies more manageable. I am less keen on the idea of pulling the Fontawesome and Bootstrap stuff in directly, just because of the potential for maintenance awfulness. Thoughts from anyone else?

One thing we'd need to look at would be whether we'd need to maintain the old non-Go-modules version to avoid breaking existing sites....

@LisaFC
Copy link
Collaborator

LisaFC commented Apr 27, 2021

I started a thread in our discussions area too just to see if I can drive more discussion to this topic, as it's a tricky one. There are, as you say, some definite advantages, and this is something Hugo has really invested in.

Some cons I'm thinking of

  • Breaking change (the big one) - what do we want to continue to maintain? Are large, established sites willing to refactor to get updates?
  • Requires Go installation
  • Users may be more comfortable/familiar with git submodules (for all that they're a bit horrible) than Go modules
  • I haven't seen many Hugo themes implemented this way yet (from a quick skim of the Hugo themes gallery) so less real world evidence of potential painpoints.

@LisaFC
Copy link
Collaborator

LisaFC commented May 12, 2021

This should be fairly easy for users to try locally, right? (obviously it doesn't build in our Netlify preview as that assumes a submodule structure) I'm going to send a mail to the users list to try to drive some discussion/experimentation. :)

@deining
Copy link
Collaborator Author

deining commented May 12, 2021

This should be fairly easy for users to try locally, right?

Yes, correct. If they experience difficulties, I'm willing to help out here or elsewhere.

I'm going to send a mail to the users list to try to drive some discussion/experimentation. :)

I just saw your post, I will follow the disussion which will hopefully arise.

@boydkelly
Copy link
Contributor

Couple of points...
Why not indicate in the docs how to install the theme as a module? No change of code on your end. Just a footnote that its an option. Then see if there are some adopters.

But more importantly modules also open up the possibilities of separation of code and content. Having done that with Antora, I have implemented that on my own personal site with hugo and my own theme that I am refactoring to be compatible with docsy. But the point being that using modules to completely remove your docs from the hugo site generation end has huge benefits. Users can edit and maintain their docs in a git repo and neither see nor think about site management.

As pointed out above, not a lot of themes use modules (yet), and probably less use modules for content. But a documentation theme should really have this as an option if not (eventually) a default configuration.

https://www.coastsytems.net

@nathlaroche
Copy link

This should be fairly easy for users to try locally, right? (obviously it doesn't build in our Netlify preview as that assumes a submodule structure) I'm going to send a mail to the users list to try to drive some discussion/experimentation. :)

How can we get on this list? :) We are starting to use Hugo/Docsy to replace our Slate framework. We have a large team of writers working on different projects, and are implementing some of our common Hugo content (archetypes, layouts, etc.) and reusable content as Hugo modules. We would love to have Docsy be a Hugo module too. So maybe we can help with the testing? :)

@LisaFC
Copy link
Collaborator

LisaFC commented Jun 22, 2021

Hi Nathalie, our user email list is https://groups.google.com/g/docsy-users, though we largely use it for announcements now that we have discussion forums on this repo.

It would be great if you want to try it and report back, either on this PR or in our discussion: #535

(which would people prefer for further discussion on this topic?)

How can we get on this list? :) We are starting to use Hugo/Docsy to replace our Slate framework. We have a large team of writers working on different projects, and are implementing some of our common Hugo content (archetypes, layouts, etc.) and reusable content as Hugo modules. We would love to have Docsy be a Hugo module too. So maybe we can help with the testing? :)

@LisaFC
Copy link
Collaborator

LisaFC commented Jun 22, 2021

Couple of points...
Why not indicate in the docs how to install the theme as a module? No change of code on your end. Just a footnote that its an option. Then see if there are some adopters.

This is a really good idea! It's a step towards potentially adopting Docsy-as-module, without the potential for breaking changes or maintenance overhead (yet), and a way to get more feedback.

I suspect only people digging around in either the PRs or the repo discussion forum may even know that it's possible (given that it's not such a commonly used mechanism yet), so having it in the actual docs will possibly get more users trying to use the feature. We can add a link to this PR and/or the discussion forum.

But more importantly modules also open up the possibilities of separation of code and content. Having done that with Antora, I have implemented that on my own personal site with hugo and my own theme that I am refactoring to be compatible with docsy. But the point being that using modules to completely remove your docs from the hugo site generation end has huge benefits. Users can edit and maintain their docs in a git repo and neither see nor think about site management.

As pointed out above, not a lot of themes use modules (yet), and probably less use modules for content. But a documentation theme should really have this as an option if not (eventually) a default configuration.

https://www.coastsytems.net

@nathlaroche
Copy link

It would be great if you want to try it and report back, either on this PR or in our discussion: #535

(which would people prefer for further discussion on this topic?)

I'll write a note in the other discussion, thanks! :)

@geriom
Copy link
Collaborator

geriom commented Jun 25, 2021

When I run hugo server I get the following error:

Error: Error building site: TOCSS: failed to transform "scss/main.scss" (text/x-scss): SCSS processing failed: file "stdin", 
line 6, col 1: File to import not found or unreadable: ../vendor/bootstrap/scss/bootstrap.

No errors importing the modules.

@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Dec 1, 2021
@deining
Copy link
Collaborator Author

deining commented Dec 10, 2021

This patch is now outdated and was superseded by my new PR #801- Let's continue the discussion there.

@deining deining closed this Dec 10, 2021
@deining deining added the module label Jan 18, 2022
@deining deining deleted the modules branch November 5, 2022 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indicates the PR's author has signed the CLA. module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants