From e2a65eb79ec40d66fcdd1eaf1eb46ee3f84fcdfc Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 20 Jan 2020 17:34:42 -0800 Subject: [PATCH] Only parse and render content for first page initially, not all pages. --- src/Pages/ContentCache.elm | 18 +++++++++++------- src/Pages/Internal/Platform.elm | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Pages/ContentCache.elm b/src/Pages/ContentCache.elm index 826cb044..7831bd1f 100644 --- a/src/Pages/ContentCache.elm +++ b/src/Pages/ContentCache.elm @@ -111,7 +111,7 @@ pagesWithErrors cache = init : Document metadata view -> Content - -> Maybe (ContentJson String) + -> Maybe { contentJson : ContentJson String, initialUrl : Url } -> ContentCache metadata view init document content maybeInitialPageContent = parseMetadata maybeInitialPageContent document content @@ -150,7 +150,7 @@ createBuildError path decodeError = parseMetadata : - Maybe (ContentJson String) + Maybe { contentJson : ContentJson String, initialUrl : Url } -> Document metadata view -> List ( List String, { extension : String, frontMatter : String, body : Maybe String } ) -> List ( List String, Result String (Entry metadata view) ) @@ -174,11 +174,15 @@ parseMetadata maybeInitialPageContent document content = parseContent extension value document in case maybeInitialPageContent of - Just initialPageContent -> - Parsed metadata - { body = renderer initialPageContent.body - , staticData = initialPageContent.staticData - } + Just { contentJson, initialUrl } -> + if initialUrl.path == ("/" ++ String.join "/" path) then + Parsed metadata + { body = renderer contentJson.body + , staticData = contentJson.staticData + } + + else + NeedContent extension metadata Nothing -> NeedContent extension metadata diff --git a/src/Pages/Internal/Platform.elm b/src/Pages/Internal/Platform.elm index 84672ec7..56fac004 100644 --- a/src/Pages/Internal/Platform.elm +++ b/src/Pages/Internal/Platform.elm @@ -255,7 +255,7 @@ init : init pathKey canonicalSiteUrl document toJsPort viewFn content initUserModel flags url key = let contentCache = - ContentCache.init document content contentJson + ContentCache.init document content (Maybe.map (\cj -> { contentJson = cj, initialUrl = url }) contentJson) contentJson = flags