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

Move Wiki as Polykey-Docs repository acting as a CMS for polykey.io/docs #1

Closed
4 tasks done
CMCDragonkai opened this issue Jul 24, 2022 · 43 comments
Closed
4 tasks done
Assignees
Labels
documentation Improvements or additions to documentation procedure Action that must be executed r&d:polykey:supporting activity Supporting core activity

Comments

@CMCDragonkai
Copy link
Member

CMCDragonkai commented Jul 24, 2022

The wiki will be scheduled to go into the polykey.io/docs instead due to community/community#4992. GH wikis are not SEO friendly.

However the wiki is still useful way of editing information compared to editing pages on our website. So a hybrid solution is to have the wiki available but then replicate/mirror the wiki to the website.

How to do this? Well the wiki information is public, and we can use BE server to mirror the information. Because search engines cannot see the wiki anyway, it's fine to have the duplicate information.

However polykey.io is hosted by webflow which has their own custom CMS. So how to connect to an external API (possibly serverless) backend to then load custom data. Most important it must do the rendering of HTML itself, and not just a mirror the HTML and present it via SSR, not fetched from JS.

It looks like on webflow, it supports https://university.webflow.com/lesson/href-prefix which allows part of an existing website hosted by your own webserver to reverse proxy a particular url directory to webflow.

However I'm looking to do the opposite, use webflow to reverse proxy a portion of the site to an alternative location. However they only allow this for enterprise: https://webflow.com/feature/reverse-proxy-service-for-enterprise

So it looks like it will be time to to front webflow with our own reverse proxy to serve.

There are 2 options here:

  1. Use cloudflare - it is already fronting polykey.io and we can use it's page rules and maybe other features to be able to route a subdirectory to a different backend server.
  2. Run our own system on AWS, and do the routing there, and upstream to webflow for the CMS and main site... etc. Hopefully the ALB is sufficient for this.

Finally the underlying backend could work as a serverless platfrom like cloudflare workers, and then it just has to fetch the wiki markdown and render the correct page.

This does limit the wiki's formatting to what the HTML is shown. See: https://stackoverflow.com/questions/38480701/can-a-github-wiki-embed-html and https://github.com/bryanbraun/github-wiki-html-test/wiki. Note that even if github wiki itself removes those tags, the code is still in the wiki git, and when we mirror we can render that with custom CSS as well if needed. We will need to incorporate this https://webmasters.stackexchange.com/a/76927

Seems like something to be automated with pulumi when we get to it.

Tasks

  • [ ] 1. Create server backend for fetching wiki source from https://github.com/MatrixAI/Polykey.wiki.git - unnecessary as we use SSG triggered from CI/CD
  • 2. Server backend should be runnable on a "serverless" worker like cloudflare workers
  • [ ] 3. Server backend should be caching the git repository, and just fetching changes should be fast, this means filesystem state may need to be cached, either via mounted filesystem, ephemeral storage is fine - this is not necessary, as we change to using SSG triggered in the CI/CD
  • 4. Serve a simple home page from the wiki rendered markdown
  • 5. Try out Cloudflare's page rules in order to route to a server from polykey.io/docs
  • [ ] 6. Need to integrate the theme appropriately, it's not possible to partially load data from a third party inside webflow template on the backend, only custom code on the frontend, so docs server will need to satisfy the same HTML header and footer of the main website - Modify defaultKeyModifier to allow pretty urls cloudflare/kv-asset-handler#6
  • [ ] 7. Reuse the polykey.io theme, could be done through a git submodule pointing to website theme code - Modify defaultKeyModifier to allow pretty urls cloudflare/kv-asset-handler#6
  • 8. Integrate https://docusaurus.io/ as a SSG framework for rendering the wiki
@CMCDragonkai CMCDragonkai added the procedure Action that must be executed label Jul 24, 2022
@CMCDragonkai
Copy link
Member Author

CMCDragonkai commented Jul 26, 2022

I've followed https://www.milkmoonstudio.com/post/using-webflow-with-cloudflare-to-cache-and-speed-up-your-webflow-project this to setup cloudflare as a proxy to the webflow site.

So basically we now have both polykey.io and www.polykey.io acting as cloudflare proxy.

image

It was necessary to first disable SSL on webflow, for it to show the configuration necessary for non-SSL routing for cloudflare. After configuring the DNS, the SSL could be re-enabled on webflow. Cloudflare is then configured to use "Full" TLS, so between client to cloudflare proxy is cloudflare's own universal SSL, then between cloudflare and the website, it is using the origin certificate which is webflow's certificate.

On webflow it still claims that something is incorrectly configured, this is not relevant, we can just ignore it.

image

It is important to switch on "Always use HTTPS", so that any http:// gets redirected to https:// which applies to worker/pages routes too.

image

Then it is possible to create a cloudflare worker/pages to be routed from polykey.io/docs. In fact right now it is routing to just a worker that prints a hello world message.

image

The configuration for this should be setup for Matrix AI infrastructure later.

@CMCDragonkai
Copy link
Member Author

CMCDragonkai commented Jul 26, 2022

So the plan is now:

  1. Continue to use webflow as a visual design tool for the main website, it can manage the pages and blog.
  2. We create a CI/CD mirrored repository https://gitlab.com/MatrixAI/open-source/Polykey-Docs that mirrors https://github.com/MatrixAI/Polykey.wiki.git, this will provide us the ability to use a SSG to generate static HTML/CSS that can be push-deployed to Cloudflare pages.
  3. Have polykey.io/docs point to the new cloudflare pages.

It's important for us to configure the Polykey-Docs repo to prevent force pushes, and to not just pull in diverged changes. This is because there is no branch protection on the wiki for Polykey, and we wouldn't want to allow accidental force pushes.

image

Note that enabling the feature seems to only exist on premium.

@CMCDragonkai CMCDragonkai self-assigned this Jul 26, 2022
@CMCDragonkai
Copy link
Member Author

The wiki repo will now need a .gitlab-ci.yaml file that makes use of 2 tools:

  1. wrangler for push deploying to cloudflare - https://developers.cloudflare.com/workers/wrangler/commands/#pages
  2. https://docusaurus.io/ as the SSG generator

@CMCDragonkai
Copy link
Member Author

CMCDragonkai commented Jul 26, 2022

I've used https://gitpod.io to test out docusaurus, it appears to work well. We basically have to configure its docs plugin to use path: '.' to point to the root directory because the wiki on github doesn't use docs subdirectory that docusaurus is configured by default to use.

There is one point of concern. It appears some aspects of the docs plugin uses markdown "front matter" that is processed by the docs plugin. When adding front matter to the markdown files, it appears to be processed as normal markdown, so it ends up showing up.

I'm not sure to what extend we will need front-matter, or if there is a way to configure it in a different way.


I did try https://gitpod.io/#https://github.com/MatrixAI/Polykey.wiki but it didn't work... claims it is a private repo. Submitted feedback.

@CMCDragonkai
Copy link
Member Author

While playing around with docusaurus, I had this idea that a similar concept can be applied to the project docs that is going to the github pages. It seems we don't need docs and instead the CI/CD can build the docs on the fly and push into the gh-pages branch. This then allows us not to bother running npm run docs manually, and keeps our source repo more clean.

@CMCDragonkai
Copy link
Member Author

The cloudflare workers/pages is a really powerful concept, as it seems to the next iteration of microservices, it's much more limited in terms of its runtime capabilities, but at the same time, it's so much faster and easier to develop for. But reducing the "surface complexity", the system becomes alot more streamlined. It becomes little HTTP-driven functions that is then deployed anywhere, with state and logic becoming "cloud-native".

@CMCDragonkai
Copy link
Member Author

With the amount of OS packages, it would make sense to eventually lift our nixpkgs overlay to have a public overlay. The private overlay would then overlay on top of the public overlay.

This way we can have a consistent upgrade. But we would need to have an appropriate CI/CD to work with the nixpkgs overlay itself.

@CMCDragonkai
Copy link
Member Author

Ok an experiment with subdirectory shows that subpages in subdirectories in the github wiki using gollum shows up as a root level page. So subdirectories aren't really mapped accordingly.

testdir/
  testpage.md

Becomes: https://github.com/MatrixAI/Polykey/wiki/testpage

Gollum must iterate across all markdown pages. I wonder if this means it will also read in node_modules.

This means all of our docs pages in polykey.io/docs would have to similarly match gollums more primitive routing structure. Everything is just base-level.

@CMCDragonkai
Copy link
Member Author

Ok because node_modules will be ignored by .gitignore this will be fine.

But this does mean ANY markdown files in the repo will end up being rendered. There doesn't seem to be an exclusion method atm.

@CMCDragonkai
Copy link
Member Author

Then the only special pages are:

Home.md, _Footer.md, and _Sidebar.md. The _Header.md doesn't exist. And that is the only things special about the GitHub wiki system.

@CMCDragonkai
Copy link
Member Author

In the future if we also want to open PRs to the wiki repo: https://sparkbox.com/foundry/github_wiki_tutorial_for_technical_wiki_documentation. That just means a proper github repo for hosting the wiki. It would need to be a 2-way mirror, as that would then provide the ability to push changes to the GitHub wiki repo.

@CMCDragonkai
Copy link
Member Author

CMCDragonkai commented Jul 26, 2022

Atm wrangler2 isn't yet on nixpkgs. NixOS/nixpkgs#176233

There is some minor difference with respect to us, which we only need to publish:

https://developers.cloudflare.com/workers/wrangler/compare-v1-v2/

Likely it will end up as wrangler2 which should be updated when appropriate.

It can be done as a nix-shell dependency for now.

@CMCDragonkai
Copy link
Member Author

The preset classic comes with some additional dependencies:

    "@mdx-js/react": "^1.6.22",
    "clsx": "^1.2.1",
    "prism-react-renderer": "^1.3.5",
    "react": "^17.0.2",
    "react-dom": "^17.0.2"

I took them out for now, because it appears to work fine. But it is necessary for us to develop our own theme.

@CMCDragonkai
Copy link
Member Author

Ok so the first build is working along with images.

image

It appears that README.md is the default page selected. I'd want to keep README.md primarily for documentation contributors, which is why it exists. While Home.md should be kept as the primary document at the beginning to standardise between github and the generate docs.

Images was solved by using symlinks in static directory.

@CMCDragonkai
Copy link
Member Author

Setting slug: / for Home.md does end up making Home.md the default page. However a warning comes up about duplicate routes. This is not apparently a problem. But if the README.md was removed, then the warning goes away. The build still succeeds. Problem is the fact that the slug shows up on github wiki.

@CMCDragonkai
Copy link
Member Author

CMCDragonkai commented Jul 26, 2022

The usage of slug: / overrides the README.md even the warning exists. It also overrides any usage of index.md. The README.md ends up not being built at all. I wonder if Github supports anything else other than Home.md.

The warning issue can be ignored since it's only README.md that conflicts and it just gets ignored entirely by docusaurus.

@CMCDragonkai
Copy link
Member Author

And without a Home.md, github wiki doesn't render a home page, only a contents list:
image

So it looks like it is needed, and we have to use the slug: / for now until a better solution is found, maybe overriding the frontmatter with some other metadata that exists elsewhere.

@CMCDragonkai
Copy link
Member Author

Ok the wiki has gone into a new repository https://github.com/MatrixAI/Polykey-Docs which now has a license... and so on. This enables pull requests, and this means we don't have to abide by the github wiki's limited functionality. We can now use docusaurus to its full potential.

Plus it's still easy to edit the wiki by just clicking and editing the wiki on the UI.

@CMCDragonkai
Copy link
Member Author

And it also renders the frontmatter properly: https://github.com/MatrixAI/Polykey-Docs/blob/master/Home.md.

@CMCDragonkai CMCDragonkai changed the title Setup Wiki as a CMS for polykey.io/docs Move Wiki as Polykey-Docs repository acting as a CMS for polykey.io/docs Jul 27, 2022
@CMCDragonkai
Copy link
Member Author

Subsequently in the future we can also move the blog into it, or create it as a separate repository.

@CMCDragonkai
Copy link
Member Author

It appears that docusaurus serve and docusaurus start are somewhat inconsistent in their routing. And plus I don't know what this looks like on cloudflare pages. So next step I need to push up to cloudflare pages and proceed with that to get a sense of how the routing will work on polykey.io/docs.

@CMCDragonkai CMCDragonkai transferred this issue from MatrixAI/Polykey Jul 27, 2022
@CMCDragonkai
Copy link
Member Author

Ok I've got wrangler2 installed because wrangler1 doesn't actually support Cloudflare pages.

Afterwards, authentication uses 2 environment variables: CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN. The token has to be created custom with the ability to edit cloudflare pages resource under the relevant account.

The relevant command is wrangler pages publish ./dist --project-name polykey-docs.

This publishes to polykey-docs.pages.dev. And it also automatically publishes to the same branch that the git repo you already in. So if you are in branch staging, then it ends up creating a staging branch on cloudflare's pages project. This can be overridden with --branch master. Cloudflare seems to automatically pick this as a "Production" environment. Non-master branches end up as "Preview" environments. These gain their own aliases like staging.polykey-docs.pages.dev. This is the case for HEAD too which gains head.polykey-docs.pages.dev.

All pushes results in a "commit", which gives you a unique reference url to that specific deployment. Like https://618c7d4f.polykey-docs.pages.dev/.

The project name has to be lower case. And a new project is auto created if so. Interestingly enough, this means project names are global across the entire cloudflare system. Not exactly as nice as cloudflare workers, which gives you a unique subdomain first, every page project basically has its own subdomain.

Unlike cloudflare workers, you cannot just add a route from a website to a cloudflare page. Pages only gain access to custom domains or subdomains. Whereas cloudflare workers can be routed from any site.

It appears that it is recommended to use a worker to act like a proxy to the cloudflare pages, that would be a way to get polykey.io/docs to route to the static site.

However there was an intermediate product: https://developers.cloudflare.com/workers/platform/sites/start-from-existing, called workers sites. And this seems to work like a normal CF worker, which would make it routable without having to create a worker just for doing routing to the polykey-docs.pages.dev.

So we will need to investigate workers sites to see if it fits instead of pages, and if not, then we could use the polykey-docs.matrixai.workers.dev to a transparent proxy.

As per https://community.cloudflare.com/t/cloudflare-pages-http-route/389515, we might just investigate how to write a worker that routes to the page.

@CMCDragonkai
Copy link
Member Author

https://blog.cloudflare.com/subdomains-vs-subdirectories-improved-seo-part-2/ - here is an example using workers to do proxying.

Now one issue talked about there is important. If the asset paths like /images are coming out of the root domain, that would mean that the docs pages are loading images like polykey.io/images/X. But these images are actually in the CF pages domain, and not under the main polykey.io.

We would need the images to be instead loaded from polykey.io/docs/images. But we still want to preserve the paths on GitHub too...

@CMCDragonkai
Copy link
Member Author

In working with cloudflare workers, pages has their own workers system integration. This is called cloudflare pages functions. https://developers.cloudflare.com/pages/platform/functions/

There are 2 ways of deploying these functions, using a functions directory under the dist, or using _worker.js which allows one to write a function for the entire pages domain.

However I discovered another bug cloudflare/workers-sdk#1570, it doesn't work unless I'm running the wrangler pages publish ./ on the current directory.

This is still very much a beta product, so there's lots of little polishing issues here.

At any case this doesn't actually solve my problem. These worker functions still sit within the cloudflare pages system, and is not routable unlike workers as subpaths of existing domains.

So I'll need to instead deploy a proper worker, and not just cloudflare pages.

Perhaps... it's possible to use worker sites instead, it seems to work the same as a worker. Let's see what happens if I were to deploy a worker-site instead of a normal worker. A template is provided here: https://developers.cloudflare.com/workers/platform/sites/start-from-scratch

@CMCDragonkai
Copy link
Member Author

Ok moving to cloudflares workers sites worked. This is basically the same as a normal cloudflare worker, but instead it has [sites] section in the wrangler.toml that specifies a bucket = "./public". I've pointed the build to now public as it makes more sense as it is not a distribution.

It basically uploads every file in the public directory to the cloudflare KV system. Which is key-value database globally distributed like a cache. Every file has a unique file path, the entire file path is the key.

The KV is given a "namespace" and an environment variable binding:

image

image

As you can see the values of the KV is just the full content of the files verbatim. In a way it just looks like a S3 bucket, but it does have slightly different consistency behaviour compared to durable objects.

@CMCDragonkai
Copy link
Member Author

It's actually really easy to migrate between workers sites and cloudflare pages, and cloudflare pages is really missing this critical feature. So instead of the _worker.js script, you can have a full JS-based worker application inside the src. This can contain typescript, webpack configuration... etc. It appears cloudflare takes the contents of src and also does build processing on it and supports external packages installed in the project repo.

Alot of the features and behaviour of wrangler is hard to find clear explanations of.

So now polykey.io/docs and polykey.io/docs/* both route to the worker code in src/index.ts. Now we just need to write the code src/index.ts to actually properly route to the static content. Probably by referencing __STATIC_CONTENT.

Note that there's no such thing as different environments for cloudflare workers. They are just deployed to separate cloudflare workers.

image

This is unlike cloudflare pages which does support it.

Finally cloudflare worker sites is basically the same as cloudflare workers, it just does some extra automation regarding the KV upload of static assets.

Note that there is no authentication to any of these things, any auth has to be done inside the worker code. Otherwise, they have to be routed via a custom domain or a custom route that then can have cloudflare stick their firewall/access/zero trust system on top.

@CMCDragonkai
Copy link
Member Author

Cloudflare pages does appear to be a more sophisticated product, with a lot of convenience features for any kind of site deployment (the integration of functions allows a fully dynamic PHP-CGI-esque kind of site).

image

I suspect that once the routing feature becomes available to cloudflare pages, it should be simple enough to transition back to pages, while for now we stick to using worker sites.

@CMCDragonkai
Copy link
Member Author

CMCDragonkai commented Jul 28, 2022

Ok, after some wrangling, some further notes:

  1. It seems @cloudflare/kv-asset-handler has problems with assets that have spaces in their names. That is requesting Polykey Logo.png is problematic but divio_quadrant.png is no problem. This may be due to HTML entities of %20 not being processed properly.
  2. URLs with /images/X is referenced from polykey.io/images/X, this is wrong, and needs to be fixed to point to polykey.io/docs/images that is offset from where the main URL is.
  3. The offsetting seems to work automatically with docusaurus when it has its baseUrl set to docs. This causes all of its assets to be loaded as polykey.io/docs/images. However because docusaurus does not process <a> tags, these links are left as /images and not /docs/images.
  4. When using ![] it does in fact process it, but turns it into /docs/assets/images because it does some processing on the asset itself.
  5. When docusaurus processes assets, it does add a sequence of characters to them. When cloudflare uploads, it also adds another sequence. The end result is a file looking like: assets/images/divio_quadrant-8b21327c9a55ca08c6712f26bda2113c.28b2f60045.png. The former is added by docusaurus, the latter by cloudflare.
  6. Worker should perform it own redirection of trailing slash to non-trailing slash permanent redirect. So https://polykey.io/docs/ becomes https://polykey.io/docs. This is both would end up going to https://polykey.io/docs/index.html (but this is hidden and occurs on server side). And the canonical page for this is polykey.io/docs. We wold only use polykey.io/docs/ as an independent page if there was a specific view for the directory as opposed to a page. - It's actually not necessary because docusaurus already adds canonical URLs for this so polykey.io/docs/ and polykey.io/docs and polykey.io/docs/index.html all point to the same resource. The canonical URL is polykey.io/docs/. For individual pages it's actually polykey.io/docs/X, but it's interesting that it's due to the baseUrl setting.

Ok so basically it is correct to set the baseUrl to /docs/, this allows docusaurus to generate links relative to /docs/.

Additionally we need to also process the <a> tags, either by adding a base tag, or by using the remark plugin to process anchor tags as well without special require calls. If we use the require calls, it won't look nice in github.

@CMCDragonkai
Copy link
Member Author

Relevant:

I'm thinking... these are 2 solutions to the same problem. Either apply some base tag that affects how my a href links are loaded, or do some post-processing on src tags and more...

Alternatively we do definitely say /docs/images, but then provide symlinks in the /docs directory to /images in the repo. So canonical location is /images in the repo, but then we symlink /static/images -> /images AND /docs/images -> images. If this works, it's likely the easiest way that doesn't involve adding a custom tag or doing custom post-processing.

Furthermore need to try to use asset paths without any spaces in the names. Although this should likely be fixed upstream by cloudflare.

@CMCDragonkai
Copy link
Member Author

CMCDragonkai commented Jul 28, 2022

Nope the /docs/images idea doesn't work for GitHub wiki. Symlinks don't render properly. That scraps that idea.

So that leaves either using a base url or post processing img tags and anchor tags appropriately...

Actually base URL also won't work, it breaks other links. So lastly just post-process the img tags, and any file link. Quite possibly any absolute HREF in img or anchor tag must be processed appropriately.

@CMCDragonkai
Copy link
Member Author

Note that cloudflare has some protections for the workers:

  1. Firewall rules via the WAF
  2. Rate limiting

The rate limiting is actually not worth it because it's more expensive than just executing the workers themselves. You may as well just pay the cost of worker execution as part of the bundled plan. It can be useful if you want to rate limit IPs specifically to allow fair usage across different client IPs.

This leaves the firewall, which you can set rules to block certain traffic. By default cloudflare does not have any kind of layer 7 protection. This has to be done manually via the WAF.

@CMCDragonkai
Copy link
Member Author

Posted new bug: cloudflare/workers-sdk#4970.

@CMCDragonkai
Copy link
Member Author

Ok what's left to do is:

  1. Force processing of anchor links and img src tags so that /images works.
  2. Fix the side bar so we can use a custom layout
  3. Bring in the Polykey theme as a custom theme - this can be done later as separate issue

@CMCDragonkai CMCDragonkai added the documentation Improvements or additions to documentation label Jul 29, 2022
@CMCDragonkai
Copy link
Member Author

So docusaurus uses 2 types of plugins in process markdown: remark and rehype. Remark works on the markdown AST, while rehype works on hypertext AST.

It seems pretty simple to create these plugins https://docusaurus.io/docs/markdown-features/plugins#creating-new-rehyperemark-plugins. So I'm still not entirely sure which one is the right one for finding the <img src="" /> attribute so let's just do recon by fire (or a sanity check).

@CMCDragonkai
Copy link
Member Author

The image links are all sorted now.

I got 2 versions of the plugin:

/**
 * Docusaurus does not process JSX `<img src ="...">` URLs
 * This plugin rewrites the URLs to be relative to `baseUrl`
 * Markdown links `[]()`, images `![](/image)` and anchor `<a href="...">`
 * are already automatically processed
 */
const remarkImageSrcWithBase = (options) => {
  return (ast) => {
    visit(ast, 'jsx', (node) => {
      const matches = node.value.match(/^(<img\s.*?src="\s*)\/(.*)$/);
      if (matches != null) {
        node.value = `${matches[1]}${baseUrl}${matches[2]}`;
      }
    });
  };
};

/**
 * Docusaurus does not process JSX `<img src ="...">` URLs
 * This plugin rewrites the src attribute to `src={require("...").default}`
 * Markdown links `[]()`, images `![](/image)` and anchor `<a href="...">`
 * are already automatically processed
 */
const remarkImageSrcWithRequire = (options) => {
  return (ast) => {
    visit(ast, 'jsx', (node) => {
      const matches = node.value.match(/^(<img\s.*?src=)"(\s*\/.*?)"(.*)$/);
      if (matches != null) {
        node.value = `${matches[1]}{require("${matches[2]}").default}${matches[3]}`;
      }
    });
  };
};

I think the second one is better as that always uses the require() as markdown images would normally do.

@CMCDragonkai
Copy link
Member Author

CMCDragonkai commented Jul 30, 2022

Along the way, I also fixed the links to /blog... etc, which were previously suffixed to the baseUrl of /docs/. This is not well documented (https://stackoverflow.com/questions/63268853/how-do-i-link-to-non-docusaurus-defined-routes-from-a-docusuarus-footer) but:

            {
              label: 'Blog',
              href: '../blog',
              target: '_parent',
            },

Is needed, the using href and ../blog ensures that we get /blog rendered without /docs/blog. Then the target: '_parent' is necessary to ensure that the link resolves using the browser and not the JS HTML router (as it is leaving the SPA app).

Normal href="" actually have the norel options attached, this preserves some link juice.

@CMCDragonkai
Copy link
Member Author

But on the topic of SPA. I've discovered a new bug. If you go to http --verbose HEAD https://polykey.io/docs/ACL you get a 404.

However the JS takes over and then routes properly to docs/ACL. Which is why in the browser you still see the ACL page afterwards. However HTTP-wise, it's a 404.

I think the cloudflare worker is finding that it doesn't find ACL. However http --verbose HEAD https://polykey.io/docs/ACL.html does work.

This means I need to make the KV handler route as if it's an SPA. It needs to understand that /docs/ACL is the same as /docs/ACL.html.

@CMCDragonkai
Copy link
Member Author

Ok so we don't want to use SPA routing, since we do want it to show the right file on the first load for SEO purposes.

In this case, we need to ensure that either trailingSlashes: true or undefined. If it is true it seems to create another problem. This causes relative links to be relative to the last trailing slash. Which seems incorrect.

So trailingSlash: undefined is the only solution. This is what generates directories.

In cloudflare the KV asset loader will resolve things that look like directories to dir/index.html, which is what we will need.

However if /dir/ link is fetched, this will still be acceptable. We may want to provide a redirect to rewrite /dir/ to /dir. This has to be a 308 redirect. Otherwise relative links will end up not working.

@CMCDragonkai
Copy link
Member Author

Ok so the full solution was even more complicated. You need this too https://docusaurus.io/docs/markdown-features/links.

Basically this means we must use [Blah](./Blah.md) links, rather than just [](Blah).

They are considered file links. And file links get "processed" by docusaurus. This removes the .md.

On Github these links work, while Blah does not. This is because I transitioned from the wiki where those links did work, but these links do not.

So now with trailingSlashes: undefined and file links, then everything works. Even [](Home) properly gets processed into just /docs/ instead of /docs/Home. But there is a redirect from /docs/Home to /docs.

@CMCDragonkai
Copy link
Member Author

Ok this is all done. Cool so we have an SPA that is SEO-capable (that is pretty much hydrated statically), but with SPA routing in JS. Future custom functionality can be extended with teh workers.

Lastly:

  1. Fix the side bar so we can use a custom layout
  2. Bring in the Polykey theme as a custom theme - this can be done later as separate issue

Will be done in a new issue.

I'll setup the docs link in polykey.io to point to the new docs polykey.io/docs.

@CMCDragonkai
Copy link
Member Author

Webflow now feels slow compared to the docs because the docs is a SPA. I've a plan to switch over the blog to docusaurus too if we make use of it more... Then webflow becomes purely a page designer for the front page.

@CMCDragonkai
Copy link
Member Author

Should write a blog post about this.

@CMCDragonkai
Copy link
Member Author

It's actually not necessary to do this. #1 (comment)

You can use .. or . to refer to directories and this is understood. I'm now using README.md as the "index" page for a given category.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation procedure Action that must be executed r&d:polykey:supporting activity Supporting core activity
Development

No branches or pull requests

1 participant