Compare commits

..

No commits in common. "424a9700141ac4b6f6afbd9aeebda227abcd7995" and "397d4ea0bcf774213da6bce9328b491bdd31eb8e" have entirely different histories.

5 changed files with 1 additions and 93 deletions

View File

@ -1,39 +0,0 @@
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
OS:=$(shell uname -s)
ifeq ($(origin .RECIPEPREFIX), undefined)
$(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later)
endif
.RECIPEPREFIX = >
IMAGE_NAME:=natter
TARGET :=
.PHONY: help
help:
> @grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -E 's/^([^:]*): *## */\1: /'
.PHONY: docker_test
docker_test: ## Run the rust tests
> $(MAKE) -C docker/natter_development build
> docker run --rm -i -t --mount type=tmpfs,destination=/tmp -v "$(shell readlink -f .):/source" --workdir=/source --env CARGO_TARGET_DIR=/target -v "natter-cargo-registry:/usr/local/cargo/registry" natter-development cargo test
.PHONY: docker_clippy
docker_clippy: ## Run static analysis of the code.
> $(MAKE) -C docker/natter_development build
> docker run --rm -i -t --mount type=tmpfs,destination=/tmp -v "$(shell readlink -f .):/source" --workdir=/source --env CARGO_TARGET_DIR=/target -v "natter-cargo-registry:/usr/local/cargo/registry" natter-development cargo clippy --no-deps --all-targets --all-features -- -D warnings
.PHONY: docker_format
docker_format: ## Auto-format source files.
> $(MAKE) -C docker/natter_development build
> docker run --rm -i -t --mount type=tmpfs,destination=/tmp -v "$(shell readlink -f .):/source" --workdir=/source --env CARGO_TARGET_DIR=/target -v "natter-cargo-registry:/usr/local/cargo/registry" natter-development cargo fmt
> docker run --rm -i -t --mount type=tmpfs,destination=/tmp -v "$(shell readlink -f .):/source" --workdir=/source --env CARGO_TARGET_DIR=/target -v "natter-cargo-registry:/usr/local/cargo/registry" natter-development prettier --write --no-error-on-unmatched-pattern "default_environment/**/*.js" "default_environment/**/*.css"
.PHONY: clean
clean:
> $(MAKE) -C docker/natter_development clean

View File

@ -21,14 +21,12 @@ help:
.PHONY: build .PHONY: build
build: ## Build the docker image. build: ## Build the docker image.
> docker build --tag $(IMAGE_NAME) --target=$(TARGET) --file Dockerfile . > docker build --tag $(IMAGE_NAME) --target=$(TARGET) --file Dockerfile .
> docker volume create natter-cargo-registry
.PHONY: shell .PHONY: shell
shell: ## Launch an interactive shell inside the docker image with the source repository mounted at /source. shell: ## Launch an interactive shell inside the docker image with the source repository mounted at /source.
shell: build shell: build
> docker run --rm -i -t --entrypoint /bin/sh --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source" --workdir=/source --env CARGO_TARGET_DIR=/target -v "natter-cargo-registry:/usr/local/cargo/registry" $(IMAGE_NAME) > docker run --rm -i -t --entrypoint /bin/sh --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source" --workdir=/source $(IMAGE_NAME)
.PHONY: clean .PHONY: clean
clean: clean:
> docker rmi $(IMAGE_NAME) > docker rmi $(IMAGE_NAME)
> docker volume rm natter-cargo-registry

View File

@ -1,11 +1,8 @@
use std::ffi::OsStr; use std::ffi::OsStr;
use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use include_dir::include_dir; use include_dir::include_dir;
use include_dir::Dir; use include_dir::Dir;
use tokio::task::JoinHandle;
use walkdir::WalkDir;
use crate::config::Config; use crate::config::Config;
use crate::context::RenderBlogPostPage; use crate::context::RenderBlogPostPage;
@ -199,27 +196,6 @@ impl SiteRenderer {
} }
Ok(()) Ok(())
} }
pub(crate) async fn copy_static_files(&self, config: &Config) -> Result<(), CustomError> {
let static_files_directory = config
.get_root_directory()
.join(config.get_relative_path_to_static_files());
if !static_files_directory.exists() {
return Ok(());
}
let static_files = get_all_files(&static_files_directory)?;
for entry in static_files {
let (path, contents) = entry.await??;
let relative_path = path.strip_prefix(&static_files_directory)?;
let output_path = self.output_directory.join(relative_path);
let parent_directory = output_path
.parent()
.ok_or("Output file should have a containing directory.")?;
tokio::fs::create_dir_all(parent_directory).await?;
tokio::fs::write(output_path, contents).await?;
}
Ok(())
}
} }
fn build_name_contents_pairs<'a>( fn build_name_contents_pairs<'a>(
@ -234,25 +210,3 @@ fn build_name_contents_pairs<'a>(
let contents = std::str::from_utf8(entry.contents())?; let contents = std::str::from_utf8(entry.contents())?;
Ok((name, contents)) Ok((name, contents))
} }
fn get_all_files<P: AsRef<Path>>(
root_dir: P,
) -> Result<impl Iterator<Item = JoinHandle<std::io::Result<(PathBuf, Vec<u8>)>>>, walkdir::Error> {
let files = WalkDir::new(root_dir)
.into_iter()
.filter(|e| match e {
Ok(dir_entry) => dir_entry.file_type().is_file(),
Err(_) => true,
})
.collect::<Result<Vec<_>, _>>()?;
let org_files = files
.into_iter()
.map(walkdir::DirEntry::into_path)
.map(|path| tokio::spawn(read_file(path)));
Ok(org_files)
}
async fn read_file(path: PathBuf) -> std::io::Result<(PathBuf, Vec<u8>)> {
let contents = tokio::fs::read(&path).await?;
Ok((path, contents))
}

View File

@ -25,7 +25,6 @@ pub(crate) async fn build_site(args: BuildArgs) -> Result<(), CustomError> {
renderer.render_blog_posts(&config).await?; renderer.render_blog_posts(&config).await?;
renderer.render_blog_stream(&config).await?; renderer.render_blog_stream(&config).await?;
renderer.render_stylesheets().await?; renderer.render_stylesheets().await?;
renderer.copy_static_files(&config).await?;
Ok(()) Ok(())
} }

View File

@ -88,8 +88,4 @@ impl Config {
.and_then(|stream| stream.entries_per_page) .and_then(|stream| stream.entries_per_page)
.unwrap_or(5) .unwrap_or(5)
} }
pub(crate) fn get_relative_path_to_static_files(&self) -> PathBuf {
Path::new("static").into()
}
} }