Skip to content

Commit

Permalink
feat(website): ✨ added size optimizations plugin to website
Browse files Browse the repository at this point in the history
Note: there's still a size increase from the plugins system that'll be helped by #66.
  • Loading branch information
arctic-hen7 committed Oct 19, 2021
1 parent 7b2ff84 commit 60e2658
Show file tree
Hide file tree
Showing 42 changed files with 42 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
- run: cargo install bonnie
- run: cargo install wasm-pack
- run: npm install
working-directory: website/website
working-directory: website
- name: Build website
run: bonnie site deploy-prod
- name: Deploy website to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: website/website/pkg
publish_dir: website/pkg
publish_branch: gh-pages
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = [
"packages/*",
"examples/*",
"website/website",
"website",
# We have the CLI subcrates as workspace members so we can actively develop on them
# They also can't be a workspace until nested workspaces are supported
"examples/basic/.perseus",
Expand Down
41 changes: 20 additions & 21 deletions bonnie.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,48 @@ dev.subcommands.example.args = [ "example" ]
dev.subcommands.example.desc = "serves the given example using a live version of the cli"

site.subcommands.export.cmd = [
"bonnie copy-subcrates",
"cd packages/perseus-cli",
# Point this live version of the CLI at the given example
"find ../../website/website -not -path \"../../website/website/.perseus/*\" -not -path \"../../website/website/target/*\" | entr -s \"TEST_EXAMPLE=../../website/website cargo run -- export\""
"cd website",
"find . -not -path \".perseus/*\" -not -path \"target/*\" | entr -s \"perseus export\""
]
site.subcommands.export.desc = "exports the site, watching for changes"
site.subcommands.serve.cmd = [
"cd website/website",
"cd website",
"browser-sync start --server \".perseus/dist/exported\" --files .perseus/dist --no-open --port 8080 --extensions html"
]
site.subcommands.serve.desc = "serves the site's exported content"
site.subcommands.tinker.cmd = [
"cd website",
"perseus tinker"

]
site.subcommands.tinker.desc = "runs tinkers on the website"
site.subcommands.build-tailwind.cmd = [
"cd website/website",
"cd website",
"tailwindcss -c ./tailwind.config.js -o ./static/tailwind.css"
]
site.subcommands.build-tailwind.desc = "builds a tailwind stylesheet for development (no purging)"
site.subcommands.build-tailwind.subcommands.prod.cmd = [
"cd website/website",
"cd website",
"NODE_ENV=production npx tailwindcss -c ./tailwind.config.js -o ./static/tailwind.css --minify"
]
site.subcommands.build-tailwind.subcommands.prod.desc = "builds a tailwind stylesheet for production (purging and minifying)"
site.subcommands.deploy.cmd = [
"bonnie site build-tailwind prod",
"bonnie copy-subcrates",
"cd packages/perseus-cli",
"cd website",
# Point this live version of the CLI at the given example
"TEST_EXAMPLE=../../website/website PERSEUS_BASE_PATH=http://localhost:8080/perseus cargo run -- deploy -e"
"PERSEUS_BASE_PATH=http://localhost:8080/perseus perseus deploy -e"

]
site.subcommands.deploy.desc = "builds the website for production and finalizes it at `website/website/pkg`"
site.subcommands.deploy.desc = "builds the website for production and finalizes it at `website/pkg`"
site.subcommands.deploy-prod.cmd = [
"mkdir -p examples/basic/.perseus/dist && mkdir -p examples/basic/.perseus/dist/static && mkdir -p examples/basic/.perseus/dist/exported",
"bonnie copy-subcrates",
"bonnie site build-tailwind prod",
"cd packages/perseus-cli",
"cd website",
# Point this live version of the CLI at the given example
"TEST_EXAMPLE=../../website/website PERSEUS_BASE_PATH=https://arctic-hen7.github.io/perseus cargo run -- deploy -e"

"PERSEUS_BASE_PATH=https://arctic-hen7.github.io/perseus perseus deploy -e"
]
site.subcommands.deploy-prod.desc = "builds the website for production on GitHub Pages and finalizes it at `website/website/pkg`"
site.subcommands.deploy-prod.desc = "builds the website for production on GitHub Pages and finalizes it at `website/pkg`"
site.subcommands.deploy.subcommands.serve.cmd = [
"cd website/website",
"cd website",
"mkdir pkgs",
"mv pkg pkgs/perseus",
"mv pkgs pkg",
Expand All @@ -83,10 +83,9 @@ site.subcommands.deploy.subcommands.serve.cmd = [
site.subcommands.deploy.subcommands.serve.desc = "serves the website for local testing after it's been built for production"
site.subcommands.run.cmd = [
"bonnie site build-tailwind",
"bonnie copy-subcrates",
"cd packages/perseus-cli",
"cd website",
# Point this live version of the CLI at the given example
"TEST_EXAMPLE=../../website/website cargo run -- serve",
"perseus serve",
]
site.subcommands.run.desc = "runs the website without watching for changes"

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions website/website/Cargo.toml → website/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "./README.md"

[dependencies]
# We use the current version of Perseus, not the local one
perseus = { path = "../../packages/perseus", version = "0.3.0-beta.13" }
perseus = "0.3.0-beta.13"
sycamore = "0.6"
sycamore-router = "0.6"
serde = "1"
Expand All @@ -24,4 +24,4 @@ pulldown-cmark = "0.8"
lazy_static = "1"
web-sys = { version = "0.3", features = [ "Event", "EventTarget" ] }
wasm-bindgen = "0.2"
wee_alloc = "0.4"
perseus-size-opt = "0.1"
6 changes: 1 addition & 5 deletions website/website/README.md → website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

This directory contains the website for Perseus, which is hosted at <https://arctic-hen7.github.io/perseus>!

## Why is this in `website/website`?

So that using the local version of Perseus rather than the most recently published release works without any further changes. In development, this is designed to work for the `examples/` directory, using `../../` to access `packages`. We mimic the same file structure here.

## Comparisons

The website includes a [comparisons page](https://arctic-hen7.github.io/perseus/comparisons), which compares Perseus to a number of other frameworks. Of course, there are _a lot_ of frameworks out there, so we highly encourage contributions to this! It's designed to be quite easy to contribute to, just add a new file called `website/website/comparisons/framework.json` (substituting `framework` for the name of the framework) and fill in the following framework details:
The website includes a [comparisons page](https://arctic-hen7.github.io/perseus/comparisons), which compares Perseus to a number of other frameworks. Of course, there are _a lot_ of frameworks out there, so we highly encourage contributions to this! It's designed to be quite easy to contribute to, just add a new file called `website/comparisons/framework.json` (substituting `framework` for the name of the framework) and fill in the following framework details:

- `name`: `String`,
- `supports_ssg`: `"full"`/`"partial"`/`"none"`,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions website/website/src/lib.rs → website/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

mod components;
mod error_pages;
mod templates;

use perseus::define_app;
use perseus::{define_app, plugins::Plugins};
use perseus_size_opt::{perseus_size_opt, SizeOpts};

define_app! {
templates: [
Expand All @@ -17,5 +15,6 @@ define_app! {
locales: {
default: "en-US",
other: []
}
},
plugins: Plugins::new().plugin(perseus_size_opt(), SizeOpts::default())
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn parse_md_to_html(markdown: &str) -> String {
lazy_static! {
/// The latest version of the documentation. This will need to be updated as the docs are from the `docs/stable.txt` file.
static ref DOCS_MANIFEST: DocsManifest = {
let contents = fs::read_to_string("../../../docs/manifest.json").unwrap();
let contents = fs::read_to_string("../../docs/manifest.json").unwrap();
serde_json::from_str(&contents).unwrap()
};
}
Expand Down Expand Up @@ -142,7 +142,7 @@ pub async fn get_build_state(path: String, locale: String) -> RenderFnResultWith
path_vec[1..].join("/") // The rest of the path
)
};
let fs_path = format!("../../../{}.md", fs_path);
let fs_path = format!("../../{}.md", fs_path);
// Read that file
let contents = fs::read_to_string(&fs_path)?;

Expand All @@ -166,8 +166,8 @@ pub async fn get_build_state(path: String, locale: String) -> RenderFnResultWith
// If we're on the `next` version, read from the filesystem directly
// Otherwise, use Git to get the appropriate version (otherwise we get #60)
let incl_contents = if version == "next" {
// Add a `../../../` to the front so that it's relative from `.perseus/`, where we are now
fs::read_to_string(format!("../../../{}", &incl_path))?
// Add a `../../` to the front so that it's relative from `.perseus/`, where we are now
fs::read_to_string(format!("../../{}", &incl_path))?
} else {
// Get the corresponding history point for this version
let history_point = DOCS_MANIFEST.history_map.get(version);
Expand All @@ -176,7 +176,7 @@ pub async fn get_build_state(path: String, locale: String) -> RenderFnResultWith
None => panic!("docs version '{}' not present in history map", version),
};
// We want the path relative to the root of the project directory (where the Git repo is)
get_file_at_version(incl_path, history_point, PathBuf::from("../../../"))?
get_file_at_version(incl_path, history_point, PathBuf::from("../../"))?
};
// Now replace the whole directive (trimmed though to preserve any whitespace) with the file's contents
contents_with_incls = contents_with_incls.replace(&line, &incl_contents);
Expand All @@ -199,8 +199,8 @@ pub async fn get_build_state(path: String, locale: String) -> RenderFnResultWith
// If we're on the `next` version, read from the filesystem directly
// Otherwise, use Git to get the appropriate version (otherwise we get #60)
let incl_contents_full = if version == "next" {
// Add a `../../../` to the front so that it's relative from `.perseus/`, where we are now
fs::read_to_string(format!("../../../{}", &incl_path))?
// Add a `../../` to the front so that it's relative from `.perseus/`, where we are now
fs::read_to_string(format!("../../{}", &incl_path))?
} else {
// Get the corresponding history point for this version
let history_point = DOCS_MANIFEST.history_map.get(version);
Expand All @@ -209,7 +209,7 @@ pub async fn get_build_state(path: String, locale: String) -> RenderFnResultWith
None => panic!("docs version '{}' not present in history map", version),
};
// We want the path relative to the root of the project directory (where the Git repo is)
get_file_at_version(incl_path, history_point, PathBuf::from("../../../"))?
get_file_at_version(incl_path, history_point, PathBuf::from("../../"))?
};
// Get the specific lines wanted
let incl_contents_lines = incl_contents_full
Expand Down Expand Up @@ -249,7 +249,7 @@ pub async fn get_build_state(path: String, locale: String) -> RenderFnResultWith
.unwrap();

// Get the sidebar from `SUMMARY.md`
let sidebar_fs_path = format!("../../../docs/{}/{}/SUMMARY.md", &version, &locale);
let sidebar_fs_path = format!("../../docs/{}/{}/SUMMARY.md", &version, &locale);
let sidebar_contents = fs::read_to_string(&sidebar_fs_path)?;
// Replace all links in that file with localized equivalents with versions as well (with the base path added)
// That means unversioned paths will redirect to the appropriate stable version
Expand Down Expand Up @@ -289,18 +289,18 @@ pub async fn get_build_paths() -> RenderFnResult<Vec<String>> {
// We start off by rendering the `/docs` page itself as an alias
let mut paths: Vec<String> = vec!["".to_string()];
// Get the `docs/` directory (relative to `.perseus/`)
let docs_dir = PathBuf::from("../../../docs");
let docs_dir = PathBuf::from("../../docs");
// Loop through it
for entry in WalkDir::new(docs_dir) {
let entry = entry?;
let path = entry.path();
// Ignore any empty directories or the like
if path.is_file() {
// This should all pass, there are no non-Unicode filenames in the docs (and i18n titles are handled outside filenames)
// Also, all these are relative, which means we can safely strip away the `../../../docs/`
// Also, all these are relative, which means we can safely strip away the `../../docs/`
// We also remove the file extensions (which are all `.md`)
let path_str = path.to_str().unwrap().replace(".md", "");
let path_str = path_str.strip_prefix("../../../docs/").unwrap();
let path_str = path_str.strip_prefix("../../docs/").unwrap();
// Only proceed for paths in the default locale (`en-US`), which we'll use to generate paths
// Also disallow any of the `SUMMARY.md` files at this point (the extension has been stripped)
// Also disallow the manifest file
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.

0 comments on commit 60e2658

Please sign in to comment.