Skip to content

Commit 0f0512e

Browse files
committed
Adds SEO tag support
1 parent 6ee460c commit 0f0512e

File tree

9 files changed

+231
-36
lines changed

9 files changed

+231
-36
lines changed

crates/docapella/src/builder.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::file_gatherer::gather_files;
22
use crate::Result;
33
use std::path::Path;
44

5-
use libdoctave::content_api::ViewMode;
5+
use libdoctave::content_api::{Site, ViewMode};
66
use libdoctave::{renderer::Renderer, ContentApiResponse, Project, ResponseContext};
77
use owo_colors::{OwoColorize as _, Stream};
88
use rayon::prelude::*;
@@ -96,6 +96,20 @@ pub(crate) fn build<W: std::io::Write>(
9696
ctx.view_mode = view_mode.clone();
9797
ctx.options.bust_image_caches = true;
9898

99+
// Set the domain based on view mode
100+
ctx.site = match view_mode {
101+
ViewMode::Dev => Site::with_domain("http://localhost:8080"),
102+
ViewMode::Prod => {
103+
// In production, use the configured domain (validation ensures it exists)
104+
Site::with_domain(
105+
project.settings.domain.clone().unwrap_or_else(|| {
106+
// This should not happen as verification should catch missing domain
107+
"https://www.example.com".to_string()
108+
})
109+
)
110+
}
111+
};
112+
99113
let response = ContentApiResponse::content(page, &project, ctx);
100114

101115
let rendered = renderer.render_page(response).map_err(|e| {

crates/docapella/src/commands/build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod tests {
3232

3333
fs::write(
3434
working_dir.path().join("docapella.yaml"),
35-
"---\ntitle: Hello World",
35+
"---\ntitle: Hello World\ndomain: https://example.com",
3636
)
3737
.unwrap();
3838
fs::write(working_dir.path().join("README.md"), "# Hello World").unwrap();
@@ -62,7 +62,7 @@ mod tests {
6262

6363
fs::write(
6464
working_dir.path().join("docapella.yaml"),
65-
"---\ntitle: Hello World",
65+
"---\ntitle: Hello World\ndomain: https://example.com",
6666
)
6767
.unwrap();
6868
fs::write(working_dir.path().join("README.md"), "# Hello World").unwrap();
@@ -94,7 +94,7 @@ mod tests {
9494

9595
fs::write(
9696
working_dir.path().join("docapella.yaml"),
97-
"---\ntitle: Hello World",
97+
"---\ntitle: Hello World\ndomain: https://example.com",
9898
)
9999
.unwrap();
100100
fs::write(working_dir.path().join("README.md"), "# Hello World").unwrap();
@@ -143,7 +143,7 @@ mod tests {
143143
let fake_stdout = String::from_utf8(fake_stdout.into_inner()).unwrap();
144144

145145
assert!(
146-
fake_stdout.contains("Found 1 issues while building documentation"),
146+
fake_stdout.contains("Found 2 issues while building documentation"),
147147
"Verification errors not logged"
148148
);
149149

crates/libdoctave/src/content_api.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,18 @@ pub struct Site {
108108

109109
impl Site {
110110
pub fn stub() -> Self {
111+
Site::with_domain("https://www.example.com")
112+
}
113+
114+
pub fn with_domain(domain: impl Into<String>) -> Self {
111115
Site {
112116
id: 0,
113117
team_id: 0,
114118
slug: "placeholder-project".to_string(),
115119
versions: vec![],
116120
integrations: Integrations::default(),
117121
collecting_feedback: false,
118-
canonical_domain: "https://www.example.com".to_string(),
122+
canonical_domain: domain.into(),
119123
}
120124
}
121125
}
@@ -688,7 +692,7 @@ mod test {
688692
},
689693
InputFile {
690694
path: PathBuf::from(SETTINGS_FILE_NAME),
691-
content: InputContent::Text(String::from("---\ntitle: An Project")),
695+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
692696
},
693697
InputFile {
694698
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -946,7 +950,7 @@ mod test {
946950
},
947951
InputFile {
948952
path: PathBuf::from(SETTINGS_FILE_NAME),
949-
content: InputContent::Text(String::from("---\ntitle: An Project")),
953+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
950954
},
951955
InputFile {
952956
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -1460,7 +1464,7 @@ mod test {
14601464
},
14611465
InputFile {
14621466
path: PathBuf::from(SETTINGS_FILE_NAME),
1463-
content: InputContent::Text(String::from("---\ntitle: An Project")),
1467+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
14641468
},
14651469
InputFile {
14661470
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -1513,7 +1517,7 @@ mod test {
15131517
},
15141518
InputFile {
15151519
path: PathBuf::from(SETTINGS_FILE_NAME),
1516-
content: InputContent::Text(String::from("---\ntitle: An Project")),
1520+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
15171521
},
15181522
InputFile {
15191523
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -1611,7 +1615,7 @@ mod test {
16111615
},
16121616
InputFile {
16131617
path: PathBuf::from(SETTINGS_FILE_NAME),
1614-
content: InputContent::Text(String::from("---\ntitle: An Project")),
1618+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
16151619
},
16161620
InputFile {
16171621
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -1683,7 +1687,7 @@ mod test {
16831687
},
16841688
InputFile {
16851689
path: PathBuf::from(SETTINGS_FILE_NAME),
1686-
content: InputContent::Text(String::from("---\ntitle: An Project")),
1690+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
16871691
},
16881692
InputFile {
16891693
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -1739,7 +1743,7 @@ mod test {
17391743
},
17401744
InputFile {
17411745
path: PathBuf::from(SETTINGS_FILE_NAME),
1742-
content: InputContent::Text(String::from("---\ntitle: An Project")),
1746+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
17431747
},
17441748
InputFile {
17451749
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -1799,7 +1803,7 @@ mod test {
17991803
},
18001804
InputFile {
18011805
path: PathBuf::from(SETTINGS_FILE_NAME),
1802-
content: InputContent::Text(String::from("---\ntitle: An Project")),
1806+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
18031807
},
18041808
InputFile {
18051809
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -1874,7 +1878,7 @@ mod test {
18741878
},
18751879
InputFile {
18761880
path: PathBuf::from(SETTINGS_FILE_NAME),
1877-
content: InputContent::Text(String::from("---\ntitle: An Project")),
1881+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
18781882
},
18791883
InputFile {
18801884
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -1989,7 +1993,7 @@ mod test {
19891993
},
19901994
InputFile {
19911995
path: PathBuf::from(SETTINGS_FILE_NAME),
1992-
content: InputContent::Text(String::from("---\ntitle: An Project")),
1996+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
19931997
},
19941998
InputFile {
19951999
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -2104,7 +2108,7 @@ mod test {
21042108
},
21052109
InputFile {
21062110
path: PathBuf::from(SETTINGS_FILE_NAME),
2107-
content: InputContent::Text(String::from("---\ntitle: An Project")),
2111+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
21082112
},
21092113
InputFile {
21102114
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -2164,7 +2168,7 @@ mod test {
21642168
},
21652169
InputFile {
21662170
path: PathBuf::from(SETTINGS_FILE_NAME),
2167-
content: InputContent::Text(String::from("---\ntitle: An Project")),
2171+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
21682172
},
21692173
InputFile {
21702174
path: PathBuf::from(NAVIGATION_FILE_NAME),

crates/libdoctave/src/lib.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ mod test {
281281
},
282282
InputFile {
283283
path: PathBuf::from(SETTINGS_FILE_NAME),
284-
content: InputContent::Text(String::from("---\ntitle: An Project")),
284+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
285285
},
286286
InputFile {
287287
path: PathBuf::from("README.md"),
@@ -354,7 +354,7 @@ mod test {
354354
},
355355
InputFile {
356356
path: PathBuf::from(SETTINGS_FILE_NAME),
357-
content: InputContent::Text(String::from("---\ntitle: An Project")),
357+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
358358
},
359359
InputFile {
360360
path: PathBuf::from("README.md"),
@@ -392,7 +392,7 @@ mod test {
392392
},
393393
InputFile {
394394
path: PathBuf::from(SETTINGS_FILE_NAME),
395-
content: InputContent::Text(String::from("---\ntitle: An Project")),
395+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
396396
},
397397
];
398398

@@ -416,7 +416,7 @@ mod test {
416416
},
417417
InputFile {
418418
path: PathBuf::from(SETTINGS_FILE_NAME),
419-
content: InputContent::Text(String::from("---\ntitle: An Project")),
419+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
420420
},
421421
];
422422

@@ -502,7 +502,7 @@ mod test {
502502
},
503503
InputFile {
504504
path: PathBuf::from(SETTINGS_FILE_NAME),
505-
content: InputContent::Text(String::from("---\ntitle: An Project")),
505+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
506506
},
507507
InputFile {
508508
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -534,7 +534,7 @@ mod test {
534534
},
535535
InputFile {
536536
path: PathBuf::from(SETTINGS_FILE_NAME),
537-
content: InputContent::Text(String::from("---\ntitle: An Project")),
537+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
538538
},
539539
InputFile {
540540
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -569,7 +569,7 @@ mod test {
569569
},
570570
InputFile {
571571
path: PathBuf::from(SETTINGS_FILE_NAME),
572-
content: InputContent::Text(String::from("---\ntitle: An Project")),
572+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
573573
},
574574
InputFile {
575575
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -608,7 +608,7 @@ mod test {
608608
},
609609
InputFile {
610610
path: PathBuf::from(SETTINGS_FILE_NAME),
611-
content: InputContent::Text(String::from("---\ntitle: An Project")),
611+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
612612
},
613613
InputFile {
614614
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -639,7 +639,7 @@ mod test {
639639
},
640640
InputFile {
641641
path: PathBuf::from(SETTINGS_FILE_NAME),
642-
content: InputContent::Text(String::from("---\ntitle: An Project")),
642+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
643643
},
644644
InputFile {
645645
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -671,7 +671,7 @@ mod test {
671671
},
672672
InputFile {
673673
path: PathBuf::from(SETTINGS_FILE_NAME),
674-
content: InputContent::Text(String::from("---\ntitle: An Project")),
674+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
675675
},
676676
InputFile {
677677
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -706,7 +706,7 @@ mod test {
706706
},
707707
InputFile {
708708
path: PathBuf::from(SETTINGS_FILE_NAME),
709-
content: InputContent::Text(String::from("---\ntitle: An Project")),
709+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
710710
},
711711
InputFile {
712712
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -735,7 +735,7 @@ mod test {
735735
},
736736
InputFile {
737737
path: PathBuf::from(SETTINGS_FILE_NAME),
738-
content: InputContent::Text(String::from("---\ntitle: An Project")),
738+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
739739
},
740740
InputFile {
741741
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -846,7 +846,7 @@ mod test {
846846
},
847847
InputFile {
848848
path: PathBuf::from(SETTINGS_FILE_NAME),
849-
content: InputContent::Text(String::from("---\ntitle: An Project")),
849+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
850850
},
851851
InputFile {
852852
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -876,7 +876,7 @@ mod test {
876876
},
877877
InputFile {
878878
path: PathBuf::from(SETTINGS_FILE_NAME),
879-
content: InputContent::Text(String::from("---\ntitle: An Project")),
879+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
880880
},
881881
InputFile {
882882
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -936,7 +936,7 @@ mod test {
936936
},
937937
InputFile {
938938
path: PathBuf::from(SETTINGS_FILE_NAME),
939-
content: InputContent::Text(String::from("---\ntitle: An Project")),
939+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
940940
},
941941
InputFile {
942942
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -1006,7 +1006,7 @@ mod test {
10061006
},
10071007
InputFile {
10081008
path: PathBuf::from(SETTINGS_FILE_NAME),
1009-
content: InputContent::Text(String::from("---\ntitle: An Project")),
1009+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
10101010
},
10111011
InputFile {
10121012
path: PathBuf::from(NAVIGATION_FILE_NAME),
@@ -1319,7 +1319,7 @@ mod test {
13191319
},
13201320
InputFile {
13211321
path: PathBuf::from(SETTINGS_FILE_NAME),
1322-
content: InputContent::Text(String::from("---\ntitle: An Project")),
1322+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
13231323
},
13241324
InputFile {
13251325
path: PathBuf::from(NAVIGATION_FILE_NAME),

crates/libdoctave/src/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ impl Default for Project {
10591059
},
10601060
InputFile {
10611061
path: PathBuf::from(SETTINGS_FILE_NAME),
1062-
content: InputContent::Text(String::from("---\ntitle: An Project")),
1062+
content: InputContent::Text(String::from("---\ntitle: An Project\ndomain: https://example.com")),
10631063
},
10641064
InputFile {
10651065
path: PathBuf::from(NAVIGATION_FILE_NAME),

0 commit comments

Comments
 (0)