Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Revise build process to reduce amount of file moves and preparation #155

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

evankanderson
Copy link
Member

This is part 1 of a several-step process to move the site build mostly out of shell and into golang.

This produces three benefits:

  1. The golang is probably more approachable for many developers.
  2. The golang templates are applied when the content is rendered, which reduces the risk of corrupting static files, since they won't be rendered through the template.
  3. When complete, it should be possible to use a static docker image with the website and map the "docs" directory into it for live iteration using the actual website rendering.

I've clicked around in multi-build mode a fair bit and this seems to work, but if there's a good way to actually diff the sites, I'd love to learn it.

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Apr 2, 2020
@knative-prow-robot knative-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 2, 2020
@evankanderson
Copy link
Member Author

Preview site is here: https://5e8672e0ad5605000693ba15--knative.netlify.com

@evankanderson
Copy link
Member Author

Related: #158

Copy link
Contributor

@RichieEscarez RichieEscarez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry Evan! I just saw this PR pop up in my inbox. Awesome idea to move this processing into the Hugo layouts! Unfortunately, I have zero bandwidth lately so I have NOT tried any of this but I did try to add some comments that might help.

Re: "to get a diff" - Have you tried running two local builds, one using old scripts and another with these changes, and then comparing the two output folders? (they should be the same right? also note my comment about keeping unwanted files out of the directory that Hugo builds from because they will show up in the site too, many times in unwanted ways).

git clone --quiet -b "release-0.10" https://github.com/"$FORK"/docs.git temp/release/v0.10
mv temp/release/v0.10/docs content/en/v0.10-docs
mkdir -p docs # -p won't fail if the file exists
for r in $(seq 13 10); do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this smart enough to just always look for the "latest version" - 3? That way we only ever have to update the latest version number and the site will automatically build and publish only the last three archives to knative.dev?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be wonderful, but I don't know where we keep that information. I can probably make it "N" and "N-3", so there's only a single value to track. Thanks for the suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was slowly moving towards adding these smarts and pulled out the "latest version"/DEFAULTBRANCH into this file (also makes it easy to configure your own personal Netlify builds to your fork): https://github.com/knative/website/blob/master/scripts/docs-version-settings.sh

@@ -30,6 +30,10 @@ then
mv content/en/docs content/en/development
# DOCS BRANCHES
echo '------ Cloning all docs releases ------'

# TODO(Evan): Avoid the need for `mv` above and make the below just ap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to use mv because I couldnt figure out how to make "git clone" happy when trying to extract only the /docs/ folders out of each knative/docs archive branch (there are all the other files and folders in the repo that we dont want to end up in the site build).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I clone the docs outside of /content/en, and then symlink deeper into the tree. Since the clone isn't in /content/en, it isn't published at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. this then renders my concern below needless (content not in the publishing path wont get picked up automatically)

@@ -1,7 +1,24 @@
<div class="td-content">
<h1>{{ .Title }}</h1>
{{ with .Params.description }}<div class="lead">{{ . | markdownify }}</div>{{ end }}
{{ .Content }}
{{ $out := .Content}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you also test the local build too? Early on there was a lot of discrepancies between how Netlify built using Hugo and how the default local Hugo server built our content, thus the move to "building" the same way in both places.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've been using local build to test.

find . -type f -path '*/content/*.md' ! -name '*_index.md' ! -name '*README.md' \
! -name '*serving-api.md' ! -name '*eventing-contrib-api.md' ! -name '*eventing-api.md' \
! -name '*build-api.md' ! -name '*.git*' ! -path '*/.github/*' ! -path '*/hack/*' \
! -path '*/node_modules/*' ! -path '*/test/*' ! -path '*/themes/*' ! -path '*/vendor/*' \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im very close to Go illiterate but I didnt see these files obviously ignored up in the Hugo layout?

For anything here that is explicitly called out, its because Hugo will build that file into the site and add empty/no title Nav entries into our TOC. They rendered as blank spaces and are clickable but since they lacked front matter (to either add the missing meta or explicitly exclude it from the build) they get added to the site in unwanted and conflicting ways.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured out what these actually mapped to and made sure that they rendered correctly as best as I could tell.

@@ -1,7 +1,24 @@
<div class="td-content">
<h1>{{ .Title }}</h1>
{{ with .Params.description }}<div class="lead">{{ . | markdownify }}</div>{{ end }}
{{ .Content }}
{{ $out := .Content}}
{{ if not ( in (slice "README.md" "_index.md") .File.LogicalName ) }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this exclude hardcoded links to other non-Knative Repo's README.md files? Im not sure we still have or need to accommodate those links that point out to another Repo's README file today but maybe we should avoid changing those URLs if or when someone does add on in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is determining if this file's name is "README.md" or "_index.md". But I've been adding "index.md" files, so I probably need to update this.

Thanks for asking!

mv temp/release/v0.10/docs content/en/v0.10-docs
mkdir -p docs # -p won't fail if the file exists
for r in $(seq 13 10); do
CLONE="docs/release-0.${r}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a variable too for that day when Knative graduates to a MAJOR version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When that happens, I hope to rewrite more of this anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ive changed this to use the values set in https://github.com/knative/website/blob/master/scripts/docs-version-settings.sh (so on release time, this file does not need to get updated to include the recent version number)

@@ -152,7 +134,7 @@ find . -type f -path '*/content/*/*/*' -name 'README.md' \
! -path '*/contributing/*' ! -path '*/v0.6-docs/*' ! -path '*/v0.5-docs/*' \
! -path '*/v0.4-docs/*' ! -path '*/v0.3-docs/*' ! -path '*/.github/*' ! -path '*/hack/*' \
! -path '*/node_modules/*' ! -path '*/test/*' ! -path '*/themes/*' ! -path '*/vendor/*' \
-execdir bash -c 'if [ -e _index.md ]; then echo "_index.md exists - skipping ${PWD#*/}"; else mv "$1" "${1/\README/\index}"; fi' -- {} \;
-execdir bash -c 'if [ -e index.md -o -e _index.md ]; then echo "index.md or _index.md exists - skipping ${PWD#*/}"; else mv "$1" "${1/README/index}"; fi' -- {} \;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesnt apply here but I thought I'd mention that Hugo does weird stuff when both an index.md and an _index.md file exist in the same directory (the build only works as expected when only one or the other exist -> an index.md file can be used and reside alone in a folder if thats the only markdown file being build from that folder).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just avoiding overwriting an index.md with README.md. This actually went in #161 to support knative/docs#2377

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 16, 2020
@RichieEscarez
Copy link
Contributor

FYI, im back but unfortunately only at limited capacity (currently only on Fridays). Ill start here (soon hopefully) and run this through some tests to see if we can get these upgrades in.

@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 25, 2020
@RichieEscarez
Copy link
Contributor

@evankanderson I was able to get the build for the archived versions running locally with the last commit that I added but the Netlify build never recognizes the symlinks (before and after my commit to this PR) and its unclear if the archived doc versions were working before?

@RichieEscarez
Copy link
Contributor

I think I've figured this out. Ive got both my fork and local build working by swapping out the for loop for a while. Not sure why Netlify likes that better but I did read that seq was not recommended due to lack of support so Im guessing thats what was blocking.

Im still testing page links and will commit my fix here if all things look good.

@RichieEscarez RichieEscarez self-assigned this Aug 1, 2020
- switch `for` to `while` to make netlify happy
- combine /doc/ clone step with archives+symlinks step
- make sure symlinks are recreated if dir exists
- use the variables in docs-version-settings.sh
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 1, 2020
@RichieEscarez
Copy link
Contributor

@evankanderson PTAL and clean up / improve as needed. I added comments in each of my commits. Overall i got the archive builds and symlinks to work on netlify.

ISSUE: I dont think all the .md suffixes are properly being removed from URLs. This im my test fork build where 18 hyperlinks are broken because they include .md: https://5f24b8fd148d6b00081cfdb3--knative-v1.netlify.app/docs/

Im going to log off now but ill try to get back to this early next week.

@RichieEscarez
Copy link
Contributor

Digging a bit more, I think all the broken links are isolated to all of our _index.md files in which we "include" the README.md files (readfile.md). 97 files that use that shortcode.

I don't think the content of anything "included" gets processed through the updated content.html file? Im guessing the content from the readfile shortcode gets dumped in after? Is it possible to add something similar in the readfile.md?

@RichieEscarez RichieEscarez added the kind/question Further information is requested label Aug 1, 2020
@RichieEscarez
Copy link
Contributor

I think I fixed the readfile.md shortcode. Ive tested this locally and it seams to be working as expected. Ill wait for the Netlify build to test that output.

Copy link
Contributor

@RichieEscarez RichieEscarez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like i've got this all working.

@evankanderson PTAL and also verify and fix and update my choices to improve etc.

If you are okay with everything, ill add the LGTM

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: evankanderson, RichieEscarez

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [RichieEscarez,evankanderson]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@RichieEscarez
Copy link
Contributor

@mattmoor would you be able to review and validate the changes here?

@RichieEscarez RichieEscarez removed the kind/question Further information is requested label Aug 19, 2020
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 22, 2020
@knative-prow-robot
Copy link
Contributor

@evankanderson: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Base automatically changed from master to main March 8, 2021 17:38
RichieEscarez added a commit to RichieEscarez/website that referenced this pull request May 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants