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

How can a query string be read by the destination view? #268

Open
ChrisPulman opened this issue Jun 14, 2023 · 2 comments
Open

How can a query string be read by the destination view? #268

ChrisPulman opened this issue Jun 14, 2023 · 2 comments

Comments

@ChrisPulman
Copy link

Hi Dave,
I want to pass a query string from a view with a list of for example A B C topics to a view with a list of A by passing a query string in the url i.e. localhost:5080/letter?query=A

I would normally get this from the context however the query string field is null when using Statiq.

  1. Is this supported?
  2. If so how can I use it to filter the topics (topics are views named as per the query string)?

We are using Statiq.Docs V1.0.0-beta.13 to produce an updated documentation website

A little assistance would be greatly appreciated :)

There is an issue also but you may know about this -:

  • if you use dotnet run once then there is a few files which are not generated, if you then use dotnet run -l Debug all the files are then generated the first run it states 0 files already existed the second time it states that all but 6 in my case existed and the site operates as expected.

  • the same applies if you run dotnet run -- preview there is always files missing, then go to any file and add a white space to any file in the input folder, the site is built again and has no issues all the files are generated.

@daveaglick
Copy link
Member

I would normally get this from the context however the query string field is null when using Statiq.

The thing to remember here is that anywhere you have C# code (a Razor view, in a pipeline or module, etc.) that code has already been executed by the time any sort of client request is made. This is key to static generation: the code is run and the "static" site assets (I.e. HTML pages, images, JavaScript files, etc.) are all produced and finalized beforehand. This paradigm is quite different to a server-side web framework like ASP.NET where you have access to request-time things like query strings in the code. While the ASP.NET context is provided in Statiq Razor views for compatibility, anything that has to do with a live web request is null or uninitialized.

This means that if you want to interact with anything the client is doing during a request (such as the query strings they're using), you have to do it using JavaScript.

If so how can I use it to filter the topics (topics are views named as per the query string)?

One way to do this would be to generate all the topics on the page, but then use JavaScript to control their display. I personally love Vue.js for stuff like this, but there are plenty of libraries for jQuery and vanilla JavaScript that can display and sort/filter a set of data as well. Then get the query string using JavaScript, and if one is provided, filter the list of topics on the client. Does that make sense?

if you use dotnet run once then there is a few files which are not generated

This definitely isn't a known issue and is certainly some kind of bug that I haven't observed before. The Statiq website itself is generated multiple times a day from a fresh environment via GitHub Actions and, as far as I know, it's never not output a file. Are you able to discern any kind of pattern to the missing files? Is it always the same ones (maybe there's some sort of weird cycle going on where it won't generate file B until file A is on disk)?

@ChrisPulman
Copy link
Author

Hi Dave,
This is our site so far https://github.com/reactiveui/website/tree/FeatureConvertWyamToStatiq if I run it on my laptop everything generated fine most of the time, when run with Github Actions it always fails. I have commented out the API section for the short term until the Blog (posts) section is successful with Actions. There's 4 files from the theme that are not being output, they are all index pages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants