Skip to content

Commit a3f879c

Browse files
committed
fix(exporting): 🐛 fixed #73
The fix does involve putting all exported files for initial loads in their own directories. Fixes #73.
1 parent 9b63fab commit a3f879c

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

packages/perseus/src/export.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ pub async fn export_app(
6565
// We need the encoded path to reference flattened build artifacts
6666
// But we don't create a flattened system with exporting, everything is properly created in a directory structure
6767
let path_encoded = urlencoding::encode(&path).to_string();
68+
// All initial load pages should be written into their own folders, which prevents a situation of a template root page outside the directory for the rest of that template's pages (see #73)
69+
// The `.html` file extension is added when this variable is used (for contrast to the `.json`s)
70+
let initial_load_path = if path.ends_with("index") {
71+
// However, if it's already an index page, we dont want `index/index.html`
72+
path.to_string()
73+
} else {
74+
format!("{}/index", &path)
75+
};
76+
6877
// Get the template itself
6978
let template = templates.get(&template_path);
7079
let template = match template {
@@ -78,9 +87,13 @@ pub async fn export_app(
7887
};
7988
// Create a locale detection file for it if we're using i18n
8089
// These just send the app shell, which will perform a redirect as necessary
90+
// TODO put everything inside its own folder for initial loads?
8191
if locales.using_i18n {
8292
immutable_store
83-
.write(&format!("exported/{}.html", path), &html_shell)
93+
.write(
94+
&format!("exported/{}.html", &initial_load_path),
95+
&html_shell,
96+
)
8497
.await?;
8598
}
8699
// Check if that template uses build state (in which case it should have a JSON file)
@@ -97,9 +110,11 @@ pub async fn export_app(
97110
// Create a full HTML file from those that can be served for initial loads
98111
// The build process writes these with a dummy default locale even though we're not using i18n
99112
let full_html = interpolate_page_data(&html_shell, &page_data, root_id);
100-
// We don't add an extension because this will be queried directly
101113
immutable_store
102-
.write(&format!("exported/{}/{}.html", locale, &path), &full_html)
114+
.write(
115+
&format!("exported/{}/{}.html", locale, initial_load_path),
116+
&full_html,
117+
)
103118
.await?;
104119

105120
// Serialize the page data to JSON and write it as a partial (fetched by the app shell for subsequent loads)
@@ -123,7 +138,7 @@ pub async fn export_app(
123138
let full_html = interpolate_page_data(&html_shell, &page_data, root_id);
124139
// We don't add an extension because this will be queried directly by the browser
125140
immutable_store
126-
.write(&format!("exported/{}.html", &path), &full_html)
141+
.write(&format!("exported/{}.html", initial_load_path), &full_html)
127142
.await?;
128143

129144
// Serialize the page data to JSON and write it as a partial (fetched by the app shell for subsequent loads)
@@ -136,7 +151,7 @@ pub async fn export_app(
136151
.await?;
137152
}
138153
}
139-
// If we're using i18n, loop through the locales
154+
// If we're using i18n, loop through the locales to create translations files
140155
if locales.using_i18n {
141156
for locale in locales.get_all() {
142157
// Get the translations string for that

0 commit comments

Comments
 (0)