@@ -6,10 +6,11 @@ use comfy_table::presets::UTF8_FULL;
6
6
use comfy_table:: { Cell , ContentArrangement , Table } ;
7
7
use eyre:: { bail, Result } ;
8
8
use indoc:: formatdoc;
9
+ use inquire:: Text ;
9
10
use tokio:: fs;
10
11
11
12
/// Create basic site configuration TOML
12
- async fn create_config ( root : & str ) -> Result < ( ) > {
13
+ async fn create_config ( root : & str , root_url : & str , language : & str , title : & str ) -> Result < ( ) > {
13
14
let site_config = formatdoc ! (
14
15
r#"
15
16
rootUrl = '{}'
@@ -21,9 +22,9 @@ async fn create_config(root: &str) -> Result<()> {
21
22
[highlighter]
22
23
enable = false
23
24
# engine = 'prism' # Can be 'prism' or 'hljs'. Defaults to 'prism'"# ,
24
- "http://localhost:3030" , // this is the default port
25
- "en-us" ,
26
- root . to_owned ( ) ,
25
+ root_url , // this is the default port
26
+ language ,
27
+ title ,
27
28
whoami:: username( )
28
29
) ;
29
30
// TBD: add Windows separator support
@@ -92,7 +93,7 @@ async fn create_directories(path: &str) -> Result<()> {
92
93
Ok ( ( ) )
93
94
}
94
95
95
- pub async fn init ( name : & str ) -> Result < ( ) > {
96
+ pub async fn init ( name : & str , prompt : bool ) -> Result < ( ) > {
96
97
let path_exists = fs:: try_exists ( name) . await ?;
97
98
98
99
if path_exists {
@@ -103,12 +104,38 @@ pub async fn init(name: &str) -> Result<()> {
103
104
path. display( )
104
105
) ;
105
106
} else {
107
+ // Prompt site configuration if wanted, otherwise fallback to sane default values
108
+ let root_url = if prompt {
109
+ Text :: new ( "Site URL:" )
110
+ . with_default ( "http://localhost:3030" )
111
+ . with_help_message ( "URL to your production site" )
112
+ . prompt ( ) ?
113
+ } else {
114
+ String :: from ( "http://localhost:3030" )
115
+ } ;
116
+ let language = if prompt {
117
+ Text :: new ( "Site language:" )
118
+ . with_default ( "en-US" )
119
+ . with_help_message ( "Your site language" )
120
+ . prompt ( ) ?
121
+ } else {
122
+ String :: from ( "en-US" )
123
+ } ;
124
+ let title = if prompt {
125
+ Text :: new ( "Site title:" )
126
+ . with_default ( name)
127
+ . with_help_message ( "Site title" )
128
+ . prompt ( ) ?
129
+ } else {
130
+ String :: from ( name)
131
+ } ;
132
+
106
133
// Create site directories
107
134
create_directories ( name) . await ?;
108
135
109
136
// Create initial files
110
137
// TBD: Basic HTML templates
111
- create_config ( name) . await ?;
138
+ create_config ( name, & root_url , & language , & title ) . await ?;
112
139
create_index_norg ( name) . await ?;
113
140
create_html_templates ( name) . await ?;
114
141
create_assets ( name) . await ?;
@@ -131,7 +158,7 @@ pub async fn init(name: &str) -> Result<()> {
131
158
. add_row ( vec ! [ Cell :: new( "templates" ) , Cell :: new( "HTML templates" ) ] )
132
159
. add_row ( vec ! [
133
160
Cell :: new( "assets" ) ,
134
- Cell :: new( "Site assets (JS, CSS, favicon , etc)" ) ,
161
+ Cell :: new( "Site assets (JS, CSS, images , etc)" ) ,
135
162
] )
136
163
. add_row ( vec ! [ Cell :: new( "theme" ) , Cell :: new( "Site theme files" ) ] )
137
164
. add_row ( vec ! [ Cell :: new( ".build" ) , Cell :: new( "Dev server artifacts" ) ] ) ;
0 commit comments