Skip to content

Build blog and community with hugo#3558

Merged
knative-prow-robot merged 3 commits into
knative:mkdocsfrom
julz:blogaboutit
May 12, 2021
Merged

Build blog and community with hugo#3558
knative-prow-robot merged 3 commits into
knative:mkdocsfrom
julz:blogaboutit

Conversation

@julz
Copy link
Copy Markdown
Contributor

@julz julz commented May 12, 2021

Fixes #3539.
Fixes #3541.

mkhugo (1)

Builds the blog and community tabs with hugo.

Also added a little CSS to visually distinguish these links.

This works by cloning the website and community repos locally, copying blog and community in to the right places (same trick website uses in https://github.com/knative/website/blob/main/scripts/processsourcefiles.sh#L107), and then building those pieces using hugo in to the same site dir as mkdocs builds the docs.

Running:

  • Same as today: mkdocs serve previews just the main site (with live reloading previews)
  • New: ./hack/build-with-blog.sh builds to /site/ and is what we should run in the netlify build/github action.
  • New: ./hack/build-with-blog.sh serve builds to /site/ and starts a local preview server with blog/community included (but no live reloads, sorry!).
    • Please run npm install -g http-server first.

Follow on work: allow community/website to be checked out as sibling directories/cached to avoid rerunning the git clone / allow local testing of changes to these repositories.

Known issue: the library Im using to do the local preview (npm install -g serve) doesn't cope with URLs that have dots in them, like http://localhost:5000/blog/2021/01/15/version-v0.20-release/, this is just a local preview issue which can be solved by using some other tool to preview the built site/ directory, but I think we can solve that separately.
.. Fixed! Using http-server instead.

/assign @omerbensaadon @csantanapr

@google-cla google-cla Bot added the cla: yes Indicates the PR's author has signed the CLA. label May 12, 2021
@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 12, 2021
@omerbensaadon
Copy link
Copy Markdown

Love the CSS!! Also tips you off that you are about to experience a different format to the one you are currently on.

Heads up, got this error:

Error: Error building site: POSTCSS: failed to transform "scss/main.css" (text/css). Check your PostCSS installation; install with "npm install postcss-cli". See https://gohugo.io/hugo-pipes/postcss/

Going to install postcss and try again

@julz
Copy link
Copy Markdown
Contributor Author

julz commented May 12, 2021

oh yeah, you do indeed need postcss for the hugo build, and there's another library too I think it needs I forgot to document, npm install autoprefixer (maybe you already had it?). Hopefully we'll throw all this in a docker container so folks dont have to care, but in the meantime these should go in contributor guide.

@omerbensaadon
Copy link
Copy Markdown

It looks like this build off of the existing website repo, so none of the processes for posting to the blog or editing community will change?

Also, still getting this error after running npm install autoprefixer and npm install postcss-cli

@julz
Copy link
Copy Markdown
Contributor Author

julz commented May 12, 2021

It looks like this build off of the existing website repo, so none of the processes for posting to the blog or editing community will change?

correct, the build for those parts is essentially unmodified (just being driven from docs rather than other way round), so all the author workflows for docs/community should stay the same, I think

@omerbensaadon
Copy link
Copy Markdown

npm install -g postcss postcss-cli autoprefixer fixed my problem!

@omerbensaadon
Copy link
Copy Markdown

There will need to be a clean up story written to ensure that folks cannot escape into the old site, but for now, this is absolutely sufficiently de-risked. Good work @julz!

@omerbensaadon
Copy link
Copy Markdown

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label May 12, 2021
@csantanapr
Copy link
Copy Markdown
Member

Using

npm install -g postcss postcss-cli autoprefixer

Doesn't work for me

Total in 1150 ms
Error: Error building site: POSTCSS: failed to transform "scss/main.css" (text/css): Error: Loading PostCSS Plugin failed: Cannot find module 'autoprefixer'

@csantanapr
Copy link
Copy Markdown
Member

They need to be local for me to work

npm install postcss postcss-cli autoprefixer

Then it works.

❯ cat package.json
{
  "dependencies": {
    "autoprefixer": "^10.2.5",
    "postcss": "^8.2.15",
    "postcss-cli": "^8.3.1"
  }
}

Copy link
Copy Markdown
Member

@csantanapr csantanapr left a comment

Choose a reason for hiding this comment

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

Add package.json and package-lock.json

{
  "dependencies": {
    "autoprefixer": "^10.2.5",
    "postcss": "^8.2.15",
    "postcss-cli": "^8.3.1"
  }
}

this way user can just npm install at the root before running the script

@csantanapr
Copy link
Copy Markdown
Member

add temp to .gitignore

Comment thread hack/build-with-blog.sh Outdated

if [ "$1" = "serve" ]; then
pushd site
http-server
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You think is better to use python3 -m http.server 8000 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Dunno, I just picked the first thing I found that worked 😅 we need npm for autoprefixer and postcss anyway tho so doesn't seem any big reason to switch 🤷‍♂️. Might be able to make it a one liner with "npx run http-server" tho 🤔

@csantanapr
Copy link
Copy Markdown
Member

I'm done with the review, is works great.
That was very clever stuff you did here @julz 🔥

I would say lets add the package.json and package-lock.json, and the .gitignore for temp and merge it

@csantanapr
Copy link
Copy Markdown
Member

/hold

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 12, 2021
@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 12, 2021
@julz
Copy link
Copy Markdown
Contributor Author

julz commented May 12, 2021

ok, copied the package.json over from website and deleted the libraries we don't use. Also added temp and node_modules to gitignore and changed the http-server command to go via npx so everything should work after only npm i.

@csantanapr ptal!

@csantanapr
Copy link
Copy Markdown
Member

works like a charm
/unhold

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 12, 2021
@csantanapr
Copy link
Copy Markdown
Member

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label May 12, 2021
@csantanapr csantanapr added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 12, 2021
@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: csantanapr

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

The pull request process is described here

Details Needs approval from an approver in each of these files:

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

@julz
Copy link
Copy Markdown
Contributor Author

julz commented May 12, 2021

/retest

@knative-prow-robot knative-prow-robot merged commit 67fda06 into knative:mkdocs May 12, 2021
RichardJJG pushed a commit to RichardJJG/docs that referenced this pull request Jun 30, 2021
* Build blog and community with hugo

* Use http-server instead of serve

* Add package.json and ignore temp
RichardJJG pushed a commit to RichardJJG/docs that referenced this pull request Jul 1, 2021
* Build blog and community with hugo

* Use http-server instead of serve

* Add package.json and ignore temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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. kind/mkdocs lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants