Skip to content

Commit

Permalink
Include custom app header (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
jxjj authored Oct 2, 2023
1 parent 22dd4d0 commit c5161be
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/components/AppFooter/AppFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<SanitizedHTML
class="flex flex-col max-w-screen-xl mx-auto p-4 lg:p-8"
:html="instanceStore.customFooter"
:addTags="['style']"
/>
</footer>
</template>
Expand Down
15 changes: 15 additions & 0 deletions src/components/CustomAppHeader/CustomAppHeader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<div class="custom-app-header bg-transparent-black-100">
<SanitizedHTML
:html="instanceStore?.customHeader ?? ''"
:addTags="['style']"
/>
</div>
</template>
<script setup lang="ts">
import { useInstanceStore } from "@/stores/instanceStore";
import SanitizedHTML from "../SanitizedHTML/SanitizedHTML.vue";
const instanceStore = useInstanceStore();
</script>
<style scoped></style>
15 changes: 10 additions & 5 deletions src/components/SanitizedHTML/SanitizedHTML.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@
</template>
<script setup lang="ts">
import DOMPurify from "dompurify";
import { computed } from "vue";
import { computed, onMounted } from "vue";
const props = withDefaults(
defineProps<{
html: string;
removeInlineStyles?: boolean;
addTags?: string[];
}>(),
{
removeInlineStyles: false,
addTags: () => [],
}
);
const sanitizeConfig = {
FORBID_ATTR: props.removeInlineStyles ? ["style"] : [],
ADD_TAGS: ["iframe"],
ADD_TAGS: ["iframe", ...props.addTags],
// needed for <style> tags
// https://github.com/cure53/DOMPurify/issues/257#issuecomment-346384997
FORCE_BODY: props.addTags?.includes("style"),
};
const sanitizedHtml = computed(() =>
DOMPurify.sanitize(props.html, sanitizeConfig)
);
const sanitizedHtml = computed(() => {
return DOMPurify.sanitize(props.html, sanitizeConfig);
});
</script>
3 changes: 3 additions & 0 deletions src/layouts/DefaultLayout.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<template>
<div id="top" class="min-h-screen pt-18 flex flex-col">
<SkipNavLink href="#main" />
<slot name="custom-header" />
<AppHeader class="app-header top-0 w-full z-20 sticky left-0" />

<main id="main" class="flex-1 flex flex-col" tabindex="-1">
<slot />
</main>
<slot name="footer" />
<Transition name="fade">
<a
v-show="showScrollToTop"
Expand All @@ -24,6 +26,7 @@ import AppHeader from "@/components/AppHeader/AppHeader.vue";
import { ChevronUpIcon } from "@/icons";
import { useWindowScroll } from "@vueuse/core";
import SkipNavLink from "@/components/SkipNavLink/SkipNavLink.vue";
import { useInstanceStore } from "@/stores/instanceStore";
const { y: scrollY } = useWindowScroll();
Expand Down
4 changes: 4 additions & 0 deletions src/pages/HomePage/HomePage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<DefaultLayout>
<template #custom-header>
<CustomAppHeader v-if="instanceStore.customHeader" />
</template>
<SignInRequiredNotice
v-if="isReady && !canSearchAndBrowse && !instanceStore.isLoggedIn"
class="my-8 mx-4"
Expand Down Expand Up @@ -61,6 +64,7 @@ import FeaturedAssetCard from "@/components/FeaturedAssetCard/FeaturedAssetCard.
import SignInRequiredNotice from "./SignInRequiredNotice.vue";
import Notification from "@/components/Notification/Notification.vue";
import AppFooter from "@/components/AppFooter/AppFooter.vue";
import CustomAppHeader from "@/components/CustomAppHeader/CustomAppHeader.vue";
const page = ref<StaticContentPage | null>(null);
const instanceStore = useInstanceStore();
Expand Down
11 changes: 10 additions & 1 deletion src/pages/StaticContentPage/StaticContentPage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<DefaultLayout>
<template #custom-header>
<CustomAppHeader v-if="instanceStore.customHeader" />
</template>
<div
v-if="page"
class="static-page__content p-4 lg:p-8 mx-auto flex-1 w-full max-w-screen-xl"
Expand All @@ -11,17 +14,23 @@
<SanitizedHTML :html="page.content ?? ''" class="w-full" />
</div>
</div>
<AppFooter />
<template #footer>
<AppFooter v-if="instanceStore.customFooter" />
</template>
</DefaultLayout>
</template>
<script setup lang="ts">
import DefaultLayout from "@/layouts/DefaultLayout.vue";
import CustomAppHeader from "@/components/CustomAppHeader/CustomAppHeader.vue";
import SanitizedHTML from "@/components/SanitizedHTML/SanitizedHTML.vue";
import AppFooter from "@/components/AppFooter/AppFooter.vue";
import { ref, watch } from "vue";
import { ApiStaticPageResponse } from "@/types";
import { useInstanceStore } from "@/stores/instanceStore";
import api from "@/api";
const instanceStore = useInstanceStore();
const props = defineProps<{
pageId: number;
}>();
Expand Down
2 changes: 2 additions & 0 deletions src/stores/instanceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const createState = () => ({
userCanSearchAndBrowse: false,
templates: [],
}),
customHeader: ref<string | null>(null),
customFooter: ref<string | null>(null),
});

Expand Down Expand Up @@ -89,6 +90,7 @@ const actions = (state: ReturnType<typeof createState>) => ({
state.collections.value = normalizeAssetCollections(
apiResponse.collections
);
state.customHeader.value = apiResponse.customHeader;
state.customFooter.value = apiResponse.customFooter;

// add id to searchable field object from api response
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ export interface ApiInstanceNavResponse {
templates: Record<number, string>; // { templateId: templateName }
featuredAssetId: string; // featured asset for homepage
featuredAssetText: string; // text appearing above the featured asset
customHeader: string | null; // html
customFooter: string | null; // html
}

Expand Down

0 comments on commit c5161be

Please sign in to comment.