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

Assets: Support Github pages / http_prefix #197

Merged
merged 2 commits into from
Jan 21, 2022
Merged

Assets: Support Github pages / http_prefix #197

merged 2 commits into from
Jan 21, 2022

Conversation

odlp
Copy link
Contributor

@odlp odlp commented Sep 30, 2020

Hello 👋

This PR fixes asset URLs for sites built for Github pages using the default URL (like the API catalogue), in which paths are prefixed with the repo name.

Changes

  • Allow $govuk-assets-path to be overriden by implementors
  • Use Sprockets URL helpers to ensure image backround URLs in CSS account for Middleman's http_prefix setting

Context

For repo-specific Github pages, the site is deployed with the repo name prefixed in the path, e.g. https://alphagov.github.io/api-catalogue/. We'd like to use Middleman's http_prefix option to account for this path prefix, which will allow us to simplify and automate our build process.

Our Middleman config looks like this:

# Without prefix for 'middleman serve'
set(:govuk_assets_path, "/assets/govuk/assets/")

# Add '/api-catalogue/' for 'middleman build', for Github Pages compatibility
configure :build do
  set(:build_dir, "build/api-catalogue")
  set(:http_prefix, "/api-catalogue/")
  set(:govuk_assets_path, "/api-catalogue/assets/govuk/assets/")
end

With this PR all asset URLs correctly include the /api-catalogue/ prefix, and we can avoid using Middleman's activate :relative_assets feature.

References

@m-green
Copy link
Contributor

m-green commented Nov 5, 2021

See also #219

@lfdebrux lfdebrux self-requested a review January 18, 2022 14:34
@lfdebrux
Copy link
Member

Hi @odlp, sorry it took so long for us to get back to you!

I'm reviewing these changes now so we can get them merged, they look great to me, only thing is that they need to be rebased. I can do this locally, but I'm unable to push to your pull request.

Are you happy to do the rebase?

Alternatively, you can give maintainers access to push changes, which might be easier for you!

If the variable has already been set, then don't override it.
This allows implementors to adjust for other settings
(such as Middleman's http_prefix setting).
Using Sprockets helpers for asset URLs provides support for Middleman's
http_prefix feature, which is useful for sites hosted on Github pages.
@odlp
Copy link
Contributor Author

odlp commented Jan 20, 2022

Thanks @lfdebrux - PR rebased

@lfdebrux
Copy link
Member

You might also have some luck with using the relative links settings instead of http_prefix, see issue #271 (comment).

@lfdebrux
Copy link
Member

lfdebrux commented Mar 9, 2022

This change has been included in release v3.2.0.

I think there are some outstanding issues with http_prefix, however this release also includes support for relative links and assets.

You can now configure your Tech Docs Template (TDT) to build your documentation site to use relative links to pages and assets.

Support for relative links and assets was introduced in pull request #291: Support sites deployed on paths other than "/" (by generating relative links).

@odlp odlp deleted the assets-support-http-prefix branch March 9, 2022 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants