Skip to content

Commit 675a738

Browse files
committed
fix(various): fix issues from testing
1 parent 126d6ac commit 675a738

File tree

7 files changed

+36
-12
lines changed

7 files changed

+36
-12
lines changed

Diff for: crates/rari-doc/src/pages/build.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ pub fn build_doc(doc: &Doc) -> Result<BuiltDocy, DocError> {
259259
})
260260
.collect();
261261

262+
let no_indexing =
263+
doc.meta.slug == "MDN/Kitchensink" || doc.is_orphaned() || doc.is_conflicting();
264+
262265
Ok(BuiltDocy::Doc(Box::new(JsonDoADoc {
263266
doc: JsonDoc {
264267
title: doc.title().to_string(),
@@ -278,6 +281,7 @@ pub fn build_doc(doc: &Doc) -> Result<BuiltDocy, DocError> {
278281
modified,
279282
summary,
280283
popularity,
284+
no_indexing,
281285
sidebar_macro: doc.meta.sidebar.first().cloned(),
282286
source: Source {
283287
folder,
@@ -287,7 +291,6 @@ pub fn build_doc(doc: &Doc) -> Result<BuiltDocy, DocError> {
287291
},
288292
browser_compat: doc.meta.browser_compat.clone(),
289293
other_translations,
290-
..Default::default()
291294
},
292295
url: doc.meta.url.clone(),
293296
..Default::default()
@@ -333,6 +336,7 @@ pub fn build_generic_page(page: &GenericPage) -> Result<BuiltDocy, DocError> {
333336
},
334337
page_title: strcat!(page.meta.title.as_str() " | " page.meta.title_suffix.as_str()),
335338
url: page.meta.url.clone(),
339+
id: page.meta.page.clone(),
336340
})))
337341
}
338342

Diff for: crates/rari-doc/src/pages/json.rs

+2
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ where
348348
#[serde(rename_all = "camelCase")]
349349
pub struct JsonHomePageSPA {
350350
pub slug: &'static str,
351+
pub url: String,
351352
pub page_title: &'static str,
352353
pub page_description: Option<&'static str>,
353354
pub featured_articles: Vec<HomePageFeaturedArticle>,
@@ -370,4 +371,5 @@ pub struct JsonGenericPage {
370371
pub hy_data: JsonGenericHyData,
371372
pub page_title: String,
372373
pub url: String,
374+
pub id: String,
373375
}

Diff for: crates/rari-doc/src/pages/types/doc.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ impl Doc {
105105
meta.original_slug = super_doc.meta.original_slug.clone();
106106
meta.sidebar = super_doc.meta.sidebar.clone();
107107
}
108+
109+
pub fn is_orphaned(&self) -> bool {
110+
self.meta.slug.starts_with("orphaned/")
111+
}
112+
113+
pub fn is_conflicting(&self) -> bool {
114+
self.meta.slug.starts_with("orphaned/")
115+
}
108116
}
109117

110118
impl PageReader for Doc {
@@ -122,7 +130,7 @@ impl PageReader for Doc {
122130
debug!("reading doc: {}", &path.display());
123131
let mut doc = read_doc(&path)?;
124132

125-
if doc.meta.locale != Default::default() {
133+
if doc.meta.locale != Default::default() && !doc.is_conflicting() && !doc.is_orphaned() {
126134
let super_doc = Doc::page_from_slug(&doc.meta.slug, Default::default())?;
127135
if let Page::Doc(super_doc) = super_doc {
128136
doc.copy_meta_from_super(&super_doc);

Diff for: crates/rari-doc/src/pages/types/generic.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct GenericPageMeta {
2828
pub full_path: PathBuf,
2929
pub path: PathBuf,
3030
pub title_suffix: String,
31+
pub page: String,
3132
}
3233

3334
impl GenericPageMeta {
@@ -38,8 +39,9 @@ impl GenericPageMeta {
3839
locale: Locale,
3940
slug: String,
4041
title_suffix: &str,
41-
url: String,
42+
page: String,
4243
) -> Result<Self, DocError> {
44+
let url = strcat!("/" locale.as_url_str() "/" slug.as_str() "/" page.as_str());
4345
Ok(GenericPageMeta {
4446
title: fm.title,
4547
locale,
@@ -48,6 +50,7 @@ impl GenericPageMeta {
4850
path,
4951
full_path,
5052
title_suffix: title_suffix.to_string(),
53+
page,
5154
})
5255
}
5356
}
@@ -195,7 +198,6 @@ fn read_generic_page(
195198
let path = full_path.strip_prefix(root)?.to_path_buf();
196199
let page = path.with_extension("");
197200
let page = page.to_string_lossy();
198-
let url = strcat!("/" locale.as_url_str() "/" slug "/" page.as_ref());
199201
let slug = strcat!(slug "/" page.as_ref());
200202

201203
Ok(GenericPage {
@@ -206,7 +208,7 @@ fn read_generic_page(
206208
locale,
207209
slug.to_string(),
208210
title_suffix,
209-
url,
211+
page.to_string(),
210212
)?,
211213
raw,
212214
content_start,

Diff for: crates/rari-doc/src/pages/types/spa.rs

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ impl SPA {
130130
}))),
131131
SPAData::HomePage => Ok(BuiltDocy::HomePageSPA(Box::new(JsonHomePageSPA {
132132
slug: self.slug,
133+
url: strcat!("/" self.locale().as_url_str() "/" self.slug),
133134
page_title: self.page_title,
134135
page_description: self.page_description,
135136
featured_articles: featured_articles(

Diff for: crates/rari-doc/src/templ/render.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use super::parser::{parse, Token};
88
use super::templs::invoke;
99
use crate::error::DocError;
1010

11+
static DELIM_START: &str = ";!::::";
12+
static DELIM_END: &str = ";!::::";
13+
1114
pub struct Rendered {
1215
pub content: String,
1316
pub templs: Vec<String>,
@@ -59,7 +62,7 @@ pub fn render(env: &RariEnv, input: &str) -> Result<Rendered, DocError> {
5962
render_tokens(env, tokens, input)
6063
}
6164
fn encode_ref(index: usize, out: &mut String) -> Result<(), DocError> {
62-
Ok(write!(out, "!::::{index}::::!",)?)
65+
Ok(write!(out, "{DELIM_START}{index}{DELIM_END}",)?)
6366
}
6467

6568
pub fn render_and_decode_ref(env: &RariEnv, input: &str) -> Result<String, DocError> {
@@ -71,13 +74,13 @@ pub fn render_and_decode_ref(env: &RariEnv, input: &str) -> Result<String, DocEr
7174

7275
pub(crate) fn decode_ref(input: &str, templs: &[String]) -> Result<String, DocError> {
7376
let mut decoded = String::with_capacity(input.len());
74-
if !input.contains("!::::") {
77+
if !input.contains(";!::::") {
7578
return Ok(input.to_string());
7679
}
7780
let mut frags = vec![];
78-
for frag in input.split("!::::") {
79-
let has_ks = frag.contains("::::!");
80-
for (i, sub_frag) in frag.splitn(2, "::::!").enumerate() {
81+
for frag in input.split(DELIM_START) {
82+
let has_ks = frag.contains(DELIM_END);
83+
for (i, sub_frag) in frag.splitn(2, DELIM_END).enumerate() {
8184
if i == 0 && has_ks {
8285
frags.push(sub_frag);
8386
//decode_macro(sub_frag, &mut decoded)?;

Diff for: src/main.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,15 @@ fn main() -> Result<(), anyhow::Error> {
223223
let file = File::create(out_file).unwrap();
224224
let mut buffed = BufWriter::new(file);
225225
urls.sort();
226-
for url in urls {
226+
for url in &urls {
227227
buffed.write_all(url.as_bytes())?;
228228
buffed.write_all(b"\n")?;
229229
}
230-
println!("Took: {: >10.3?} to write sitemap.txt", start.elapsed());
230+
println!(
231+
"Took: {: >10.3?} to write sitemap.txt ({})",
232+
start.elapsed(),
233+
urls.len()
234+
);
231235
}
232236
if let Some((recorder_handler, tx)) = templ_stats {
233237
tx.send("∞".to_string())?;

0 commit comments

Comments
 (0)