Skip to content

Commit

Permalink
removed fastn 22 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Nov 24, 2024
1 parent d46e238 commit 9ca8c7d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 169 deletions.
80 changes: 2 additions & 78 deletions fastn-core/src/package/package_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,22 +365,14 @@ pub(crate) async fn read_ftd_(
main: &fastn_core::Document,
base_url: &str,
download_assets: bool,
test: bool,
_test: bool,
only_js: bool,
preview_session_id: &Option<String>,
) -> fastn_core::Result<FTDResult> {
tracing::info!(document = main.id);
match config.config.ftd_edition {
fastn_core::FTDEdition::FTD2022 => {
read_ftd_2022(
config,
main,
base_url,
download_assets,
test,
preview_session_id,
)
.await
unreachable!()
}
fastn_core::FTDEdition::FTD2023 => {
read_ftd_2023(
Expand All @@ -396,74 +388,6 @@ pub(crate) async fn read_ftd_(
}
}

#[tracing::instrument(name = "read_ftd_2022", skip_all)]
pub(crate) async fn read_ftd_2022(
config: &mut fastn_core::RequestConfig,
main: &fastn_core::Document,
base_url: &str,
download_assets: bool,
test: bool,
preview_session_id: &Option<String>,
) -> fastn_core::Result<FTDResult> {
let font_style = config.config.get_font_style();
let c = &config.config.clone();

let current_package = config
.config
.find_package_else_default(main.package_name.as_str(), None);

config.document_id.clone_from(&main.id);
config.base_url = base_url.to_string();

// Get Prefix Body => [AutoImports + Actual Doc content]
let mut doc_content =
current_package.get_prefixed_body(main.content.as_str(), main.id.as_str(), true);
// Fix aliased imports to full path (if any)
doc_content = current_package.fix_imports_in_body(doc_content.as_str(), main.id.as_str())?;

let line_number = doc_content.split('\n').count() - main.content.split('\n').count();
let main_ftd_doc = match fastn_core::doc::interpret_helper(
main.id_with_package().as_str(),
doc_content.as_str(),
config,
base_url,
download_assets,
line_number,
preview_session_id,
)
.await
{
Ok(v) => v,
Err(e) => {
tracing::error!(msg = "failed to parse", doc = main.id.as_str());
return Err(fastn_core::Error::PackageError {
message: format!("failed to parse {:?}", &e),
});
}
};

if let Some((url, code)) = main_ftd_doc.get_redirect()? {
return Ok(FTDResult::Redirect { url, code });
}

let executor = ftd::executor::ExecuteDoc::from_interpreter(main_ftd_doc)?;
let node = ftd::node::NodeData::from_rt(executor);
let html_ui = ftd::html::HtmlUI::from_node_data(node, "main", test)?;

let file_content = fastn_core::utils::replace_markers_2022(
fastn_core::ftd_html(),
html_ui,
c,
main.id_to_path().as_str(),
font_style.as_str(),
base_url,
preview_session_id,
)
.await;

Ok(FTDResult::Html(file_content.into()))
}

#[allow(clippy::await_holding_refcell_ref)]
#[tracing::instrument(name = "read_ftd_2023", skip_all)]
pub(crate) async fn read_ftd_2023(
Expand Down
90 changes: 0 additions & 90 deletions fastn-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,96 +622,6 @@ async fn get_extra_css(
)
}

#[allow(clippy::too_many_arguments)]
pub async fn replace_markers_2022(
s: &str,
html_ui: ftd::html::HtmlUI,
config: &fastn_core::Config,
main_id: &str,
font_style: &str,
base_url: &str,
session_id: &Option<String>,
) -> fastn_resolved::CompiledDocument {
ftd::html::utils::trim_all_lines(
s.replace(
"__ftd_meta_data__",
ftd::html::utils::get_meta_data(&html_ui.html_data).as_str(),
)
.replace(
"__ftd_doc_title__",
html_ui.html_data.title.unwrap_or_default().as_str(),
)
.replace("__ftd_data__", html_ui.variables.as_str())
.replace(
"__ftd_canonical_url__",
config.package.generate_canonical_url(main_id).as_str(),
)
.replace(
"__favicon_html_tag__",
resolve_favicon(
config.ds.root().to_string().as_str(),
config.package.name.as_str(),
&config.package.favicon,
&config.ds,
session_id,
)
.await
.unwrap_or_default()
.as_str(),
)
.replace("__ftd_external_children__", "{}")
.replace("__hashed_default_css__", hashed_default_css_name())
.replace("__hashed_default_js__", hashed_default_js_name())
.replace(
"__ftd__",
format!("{}{}", html_ui.html.as_str(), font_style).as_str(),
)
.replace(
"__extra_js__",
get_extra_js(
config,
config.ftd_external_js.as_slice(),
config.ftd_inline_js.as_slice(),
html_ui.js.as_str(),
html_ui.rive_data.as_str(),
session_id,
)
.await
.as_str(),
)
.replace(
"__extra_css__",
get_extra_css(
config,
config.ftd_external_css.as_slice(),
config.ftd_inline_css.as_slice(),
html_ui.css.as_str(),
session_id,
)
.await
.as_str(),
)
.replace(
"__ftd_functions__",
format!(
"{}\n{}\n{}\n{}\n{}\n{}\n{}",
html_ui.functions.as_str(),
html_ui.dependencies.as_str(),
html_ui.variable_dependencies.as_str(),
html_ui.dummy_html.as_str(),
html_ui.raw_html.as_str(),
html_ui.mutable_variable,
html_ui.immutable_variable
)
.as_str(),
)
.replace("__ftd_body_events__", html_ui.outer_events.as_str())
.replace("__ftd_element_css__", "")
.replace("__base_url__", base_url)
.as_str(),
)
}

pub fn get_fastn_package_data(package: &fastn_core::Package) -> String {
format!(
indoc::indoc! {"
Expand Down
2 changes: 1 addition & 1 deletion fastn-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ pub fn get_all_asts<'a, T: Iterator<Item = &'a fastn_resolved::Definition>>(
} else if let fastn_resolved::Definition::OrType(ot) = definition {
let mut fields = vec![];
for variant in &ot.variants {
if let Some(value) = &variant.clone().fields().get(0).unwrap().value {
if let Some(ref value) = variant.clone().fields().first().unwrap().value {
fields.push((
variant
.name()
Expand Down

0 comments on commit 9ca8c7d

Please sign in to comment.