Skip to content

Commit

Permalink
feat: optional book template creation
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Aug 4, 2024
1 parent 887b2fc commit 4cdfff2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ edition = "2021"
build-dir = "target/book"

[output.html]
cname = "GITHUB_PAGES_URL"
{% if mdbook_pages_url %}
cname = "{{ mdbook_pages_url }}"
{% endif %}
curly-quotes = true
edit-url-template = "https://github.com/{{ repository_path }}/{{ project-name }}/edit/main/{path}"
git-repository-url = "https://github.com/{{ repository_path }}/{{ project-name }}"
Expand Down
18 changes: 17 additions & 1 deletion cargo_generate_hooks/init.rhai
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
template_book();
prompt_optional_string("codecov", "Codecov token");
prompt_optional_string("architecture_url", "Architecture README.md URL");
prompt_variable("repository_path", "Repository path (usually 'username/repository_name')");

fn template_book() {
let include_mdbook = prompt_yes_no("Create mdBook template");

if !include_mdbook {
file::delete("book.toml");
file::delete("book");
}

if include_mdbook {
prompt_optional_string("mdbook_pages_url", "Publish the mdBook to repository's static pages service? If so, to which URL?");
}
}

fn prompt_variable(name: &str, prompt: &str) {
let value = variable::prompt(prompt);
variable::set(name, value);
Expand All @@ -11,10 +25,12 @@ fn prompt_optional_string(name: &str, prompt: &str) {
prompt_variable(name, `${prompt} (leave empty if none)`);
}

fn prompt_yes_no(name: &str, prompt: &str) {
fn prompt_yes_no(name: &str, prompt: &str) -> bool {
let value = switch variable::prompt(prompt, "No", ["Yes", "No"]) {
"Yes" => true,
"No" => false,
};
variable::set(name, value);

value
}
3 changes: 0 additions & 3 deletions template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@
replace_all() {
fd --type file . | xargs sed -i -e "s^$1^$2^g"
}

# Assumptions: hosted on github.com, default branch is main.
replace_all 'GITHUB_PAGES_URL' 'username.github.io'

0 comments on commit 4cdfff2

Please sign in to comment.