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

Add offline emulation of the site #5

Open
paultyng opened this issue Jul 29, 2020 · 5 comments
Open

Add offline emulation of the site #5

paultyng opened this issue Jul 29, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@paultyng
Copy link
Contributor

paultyng commented Jul 29, 2020

Ability to run something like tfplugindocs serve to browse the site locally.

@paultyng paultyng changed the title Add emulation / validation of all internal links Add offline emulation of the site Jan 26, 2021
@paultyng paultyng added the enhancement New feature or request label Jan 26, 2021
@wjam
Copy link

wjam commented Feb 13, 2021

Has any thought been given on how to implement this?

I've started putting something together that reuses https://registry.terraform.io/tools/doc-preview to avoid having duplicate implementations of the rendering of the markdown. While there are a number of things that still need to be done (mostly marked with TODO comments), would this be acceptable?

My implementation proxies requests to the doc preview page and injects enough JavaScript to show the page and support switching the content of the textarea to display the other pages.

wjam@c488aaf

@dominik-lekse
Copy link

Found this gem while working on a terraform provider.

@wjam I really like the approach for the local preview to reuse the Terraform registry doc preview tool. It is a real time saver when reviewing the documentation.

When trying the implementation at wjam@c488aaf, the browser debugger shows errors related to the X-Content-Type-Options header. I guess this is related to recent security enhancements in the browser.

Starting from wjam@c488aaf, I added the following improvements and resolved some open TODOs:

  • Use httputil.ReverseProxy in proxyRequest; this fixed the X-Content-Type-Options header violations mentions earlier
  • Embed menu template and javascript using go:embed
  • Added optional argument --addr [host:port]
  • Moved serve related code from cmd to serve
  • Find text area with query selector to avoid hard-coded id
  • Rebase to current main

Checkout the improved tfplugindocs serve in https://github.com/dominik-lekse/terraform-plugin-docs/tree/serve-docs

@paultyng Do you have an update on the planing/roadmap of the preview feature?

The approach to inject javascript/markdown in the proxy is not ideal. However, it serves the purpose well as it includes a working navigation between resources and data sources like in the real terraform registry docs.

When going with the proxy approach, one direction could be to improve the registry doc preview tool to integrate nicer with the proxy (e.g. provide a javascript function to render the markdown to avoid the textarea injection).

A fully offline preview would of course require all assets of the preview tool to be embedded in tfplugindocs and would not need a proxy. At this point, I am not sure if the source of the registry doc preview tool is available to the public.

@spikewang
Copy link

This will be really helpful when developing provider. There are several use cases here:

  1. We want to visualize and validate before publishing the new version of the provider to the registry... I could try to generate one website based on markdown, but it won't be always rendered the same as registry...
  2. We want to host our internal documentation site to always point to the latest dev branch before publishing to registry. This will serve everyone internally who want to test the latest.

@yufeiminds
Copy link

Same use case with @spikewang.

@paultyng Is there any roadmap for an offline site of terraform plugin docs?

@mattdot
Copy link

mattdot commented Oct 28, 2024

Would really love this feature. We're trying to figure out why some of our docs are rendering incorrectly and the only thing we can do between tries is publish a new version. This inconveniences our users. We should be able to verify our changes locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants