Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Document title evaluation #32

Merged
merged 3 commits into from Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ftd.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8"><base href="__base_url__">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>__ftd_doc_title__</title>
<script type="ftd" id="ftd-data">
__ftd_data__
</script>
Expand Down
17 changes: 17 additions & 0 deletions src/commands/build.rs
Expand Up @@ -258,12 +258,17 @@ async fn process_ftd(
});
}
};
let doc_title = match &main_ftd_doc.title() {
Some(x) => x.rendered.clone(),
_ => main.id.as_str().to_string(),
};
let ftd_doc = main_ftd_doc.to_rt("main", &main.id);

let mut f = tokio::fs::File::create(new_file_path).await?;
f.write_all(
fix_base(
fpm::ftd_html()
.replace("__ftd_doc_title__", doc_title.as_str())
.replace(
"__ftd_data__",
serde_json::to_string_pretty(&ftd_doc.data)
Expand Down Expand Up @@ -317,6 +322,11 @@ async fn process_ftd(
});
}
};

let doc_title = match &main_ftd_doc.title() {
Some(x) => x.rendered.clone(),
_ => main.id.as_str().to_string(),
};
let main_rt_doc = main_ftd_doc.to_rt("main", &main.id);

let message_ftd_doc = match ftd::p2::Document::from("message", message, &lib) {
Expand All @@ -334,6 +344,7 @@ async fn process_ftd(
f.write_all(
fix_base(
fpm::with_message()
.replace("__ftd_doc_title__", doc_title.as_str())
.replace(
"__ftd_data_message__",
serde_json::to_string_pretty(&message_rt_doc.data)
Expand Down Expand Up @@ -414,6 +425,11 @@ async fn process_ftd(
});
}
};

let doc_title = match &main_ftd_doc.title() {
Some(x) => x.rendered.clone(),
_ => main.id.as_str().to_string(),
};
let message_rt_doc = message_ftd_doc.to_rt("message", &main.id);

let fallback_ftd_doc =
Expand All @@ -432,6 +448,7 @@ async fn process_ftd(
f.write_all(
fix_base(
fpm::with_fallback()
.replace("__ftd_doc_title__", doc_title.as_str())
.replace(
"__ftd_data_message__",
serde_json::to_string_pretty(&message_rt_doc.data)
Expand Down
11 changes: 10 additions & 1 deletion tests/02-hello/input/amitu/index.ftd
@@ -1 +1,10 @@
-- ftd.text: hello
-- ftd.text: hello

-- ftd.text: hello_h2
region: h2

-- ftd.text: hello_h1
region: h1

-- ftd.text: hello_h0
region: h0
2 changes: 1 addition & 1 deletion tests/02-hello/output/FPM/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>FPM.ftd</title>
<script type="ftd" id="ftd-data">
{
"fpm#document-id": {
Expand Down
7 changes: 5 additions & 2 deletions tests/02-hello/output/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>hello_h0</title>
<script type="ftd" id="ftd-data">
{}
</script>
Expand Down Expand Up @@ -619,7 +619,10 @@
</head>
<body>

<div data-id="main:root" style="align-items: flex-start; align-self: center; border-radius: 0px; border-style: solid; border-width: 0px; box-sizing: border-box; display: flex; flex-direction: column; flex-wrap: wrap; height: 100%; justify-content: flex-start; margin-bottom: auto; margin-top: auto; white-space: initial; width: 100%" class="ft_md"><div data-id="0:main" style="align-self: flex-start; border-radius: 0px; border-style: solid; border-width: 0px; box-sizing: border-box; font-weight: 400; text-align: left; white-space: initial" class="ft_md">hello</div></div>
<div data-id="main:root" style="align-items: flex-start; align-self: center; border-radius: 0px; border-style: solid; border-width: 0px; box-sizing: border-box; display: flex; flex-direction: column; flex-wrap: wrap; height: 100%; justify-content: flex-start; margin-bottom: auto; margin-top: auto; white-space: initial; width: 100%" class="ft_md"><div data-id="0:main" style="align-self: flex-start; border-radius: 0px; border-style: solid; border-width: 0px; box-sizing: border-box; font-weight: 400; text-align: left; white-space: initial" class="ft_md">hello</div>
<div data-id="1:main" style="align-self: flex-start; border-radius: 0px; border-style: solid; border-width: 0px; box-sizing: border-box; font-weight: 400; text-align: left; white-space: initial" class="ft_md">hello_h2</div>
<div data-id="2:main" style="align-self: flex-start; border-radius: 0px; border-style: solid; border-width: 0px; box-sizing: border-box; font-weight: 400; text-align: left; white-space: initial" class="ft_md">hello_h1</div>
<div data-id="3:main" style="align-self: flex-start; border-radius: 0px; border-style: solid; border-width: 0px; box-sizing: border-box; font-weight: 400; text-align: left; white-space: initial" class="ft_md">hello_h0</div></div>


<script>
Expand Down
2 changes: 1 addition & 1 deletion tests/03-nested-document/output/FPM/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>FPM.ftd</title>
<script type="ftd" id="ftd-data">
{
"fpm#document-id": {
Expand Down
2 changes: 1 addition & 1 deletion tests/03-nested-document/output/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>hello</title>
<script type="ftd" id="ftd-data">
{}
</script>
Expand Down
2 changes: 1 addition & 1 deletion tests/03-nested-document/output/nested/document/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>nested document</title>
<script type="ftd" id="ftd-data">
{}
</script>
Expand Down
2 changes: 1 addition & 1 deletion tests/03-nested-document/output/nested/index/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>This should be rendered inside amitu/nested/index/index.html</title>
<script type="ftd" id="ftd-data">
{}
</script>
Expand Down
2 changes: 1 addition & 1 deletion tests/04-import-package-doc/output/FPM/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>FPM.ftd</title>
<script type="ftd" id="ftd-data">
{
"fpm#document-id": {
Expand Down
2 changes: 1 addition & 1 deletion tests/04-import-package-doc/output/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>hello</title>
<script type="ftd" id="ftd-data">
{}
</script>
Expand Down
2 changes: 1 addition & 1 deletion tests/04-import-package-doc/output/lib/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>lib.ftd</title>
<script type="ftd" id="ftd-data">
{}
</script>
Expand Down
2 changes: 1 addition & 1 deletion tests/06-hello-font/output/FPM/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>FPM.ftd</title>
<script type="ftd" id="ftd-data">
{
"fpm#document-id": {
Expand Down
2 changes: 1 addition & 1 deletion tests/09-static-assets/output/FPM/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>FPM.ftd</title>
<script type="ftd" id="ftd-data">
{
"fpm#document-id": {
Expand Down
2 changes: 1 addition & 1 deletion tests/13-translation/output/FPM/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>FPM.ftd</title>

<script type="ftd" id="ftd-data-message">
{
Expand Down
2 changes: 1 addition & 1 deletion tests/14-translation-hindi/output/FPM/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>FPM.ftd</title>

<script type="ftd" id="ftd-data-message">
{
Expand Down
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>FPM.ftd</title>
<script type="ftd" id="ftd-data">
{
"fpm#document-id": {
Expand Down
2 changes: 1 addition & 1 deletion with-fallback.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8"><base href="__base_url__">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>__ftd_doc_title__</title>

<script type="ftd" id="ftd-data-message">
__ftd_data_message__
Expand Down
2 changes: 1 addition & 1 deletion with-message.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8"><base href="__base_url__">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>ftd</title>
<title>__ftd_doc_title__</title>

<script type="ftd" id="ftd-data-message">
__ftd_data_message__
Expand Down