feat: add Settings.pages.base_path to store website content
DIRECTORY STRUCTURE: Settings.pages.base_path > page.hostname
This commit is contained in:
parent
71533b9860
commit
76692109bc
3 changed files with 23 additions and 6 deletions
|
@ -26,6 +26,10 @@ domain = "demo.librepages.org"
|
|||
cookie_secret = "94b2b2732626fdb7736229a7c777cb451e6304c147c4549f30"
|
||||
|
||||
|
||||
[page]
|
||||
base_path = "/tmp/librepages-defualt-config/"
|
||||
|
||||
|
||||
|
||||
[database]
|
||||
# This section deals with the database location and how to access it
|
||||
|
|
|
@ -84,6 +84,12 @@ pub struct Settings {
|
|||
pub source_code: String,
|
||||
pub pages: Vec<Arc<Page>>,
|
||||
pub database: Database,
|
||||
pub page: PageConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageConfig {
|
||||
pub base_path: String,
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
|
@ -174,14 +180,20 @@ impl Settings {
|
|||
pub fn init(&self) {
|
||||
for (index, page) in self.pages.iter().enumerate() {
|
||||
Url::parse(&page.repo).unwrap();
|
||||
let path = Path::new(&page.path);
|
||||
if path.exists() && path.is_file() {
|
||||
panic!("Path is a file, should be a directory: {:?}", page);
|
||||
|
||||
fn create_dir_util(path: &Path) {
|
||||
if path.exists() && path.is_file() {
|
||||
panic!("Path is a file, should be a directory: {:?}", path);
|
||||
}
|
||||
|
||||
if !path.exists() {
|
||||
std::fs::create_dir_all(&path).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
if !path.exists() {
|
||||
std::fs::create_dir_all(&path).unwrap();
|
||||
}
|
||||
create_dir_util(Path::new(&page.path));
|
||||
create_dir_util(Path::new(&self.page.base_path));
|
||||
|
||||
for (index2, page2) in self.pages.iter().enumerate() {
|
||||
if index2 == index {
|
||||
continue;
|
||||
|
|
|
@ -41,6 +41,7 @@ pub async fn get_ctx() -> (Temp, Arc<Ctx>) {
|
|||
let tmp_dir = Temp::new_dir().unwrap();
|
||||
println!("[log] Test temp directory: {}", tmp_dir.to_str().unwrap());
|
||||
let mut pages = Vec::with_capacity(settings.pages.len());
|
||||
let page_base_path = tmp_dir.as_path().join("base_path");
|
||||
for page in settings.pages.iter() {
|
||||
let name = Path::new(&page.path).file_name().unwrap().to_str().unwrap();
|
||||
let path = tmp_dir.as_path().join(name);
|
||||
|
|
Loading…
Reference in a new issue