Skip to content

Commit

Permalink
Merge branch 'develop' into feature/i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviareichl committed Nov 23, 2023
2 parents a30bc97 + bf91c54 commit 8565bc6
Show file tree
Hide file tree
Showing 27 changed files with 1,024 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/.env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
4 changes: 2 additions & 2 deletions App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
</div>
</template>
<script setup lang="ts">
const { $discoveryConfig } = useNuxtApp();
import { discoveryConfig } from '~/config/discoveryConfig';
useHead({
titleTemplate: (titleChunk) => {
return titleChunk ? `${titleChunk} - ${$discoveryConfig.title}` : $discoveryConfig.title;
return titleChunk ? `${titleChunk} - ${discoveryConfig.title}` : discoveryConfig.title;
},
link: [getFavicon()],
});
Expand Down
4 changes: 2 additions & 2 deletions components/HeaderBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ContentNavigationCNCustom />

<client-only v-if="$discoveryConfig.APIbase">
<client-only v-if="APIBase">
<v-tooltip content-class="text-capitalize" :text="$t('global.basics.map')" location="bottom">
<template #activator="{ props }">
<nuxt-link
Expand Down Expand Up @@ -43,7 +43,7 @@ const Locale = useI18n().locale;
const localePath = useLocalePath();
const logo = getHeaderLogo();
const APIBase = useRuntimeConfig().public.APIBase;
onBeforeMount(() => {
Locale.value = localStorage.getItem(selectedLocaleLocalStorageKey) ?? Locale.value;
});
Expand Down
2 changes: 1 addition & 1 deletion components/OADFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const frontenVersion = `${config.public.gitTag ?? "version"} - ${
style="font-size: 0.75em"
class="w-50 mx-auto d-flex justify-center justify-space-between align-center">
<div>
<NuxtLink style="text-decoration: none; color: inherit" to="/">Home</NuxtLink>
<NuxtLink style="text-decoration: none; color: inherit" to="/imprint">{{ $t('global.imprint') }}</NuxtLink>
</div>

<div class="text-center" >
Expand Down
13 changes: 6 additions & 7 deletions composables/oad-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { discoveryConfig } from '~/config/discoveryConfig';

export const useSafeRead = function (obj: Object, index: string): string | undefined {
const indizes = index.split(/[.[\]"']/).filter((x) => x !== "");
return indizes.reduce((o, key) => o?.[key], obj);
Expand All @@ -10,33 +12,30 @@ export const useFormatDateTime = (date: string) => {
export const selectedLocaleLocalStorageKey = "oad-selected-locale";

export function getLogo(): string {
const { $discoveryConfig } = useNuxtApp();

const logo = $discoveryConfig.logo ?? "logo.svg";
const logo = discoveryConfig.logo ?? "logo.svg";
return logo;
}

export function getHeaderLogo(): string {
const { $discoveryConfig } = useNuxtApp();

return $discoveryConfig.headerLogo ?? $discoveryConfig.logo ?? "/header_logo.svg";
return discoveryConfig.headerLogo ?? discoveryConfig.logo ?? "/header_logo.svg";
}

export function getFavicon(): { rel: string; type: string; href: string; sizes: string } {
const { $discoveryConfig } = useNuxtApp();

const favicon = {
rel: "icon",
type: "image/svg+xml",
href: "/favicon.svg",
sizes: "any",
};
const faviconExt = $discoveryConfig.favicon?.split(".").pop();
const faviconExt = discoveryConfig.favicon?.split(".").pop();

// Can Handle SVGs, .ico
if (faviconExt === "ico") {
favicon.type = "image/x-icon";
favicon.href = "/" + $discoveryConfig.favicon;
favicon.href = "/" + discoveryConfig.favicon;
}

return favicon;
Expand Down
8 changes: 5 additions & 3 deletions config/discoveryConfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"defaultLocale": "en",
"APIbase": "https://demo-dev.openatlas.eu",
"imageDomains": ["openatlas.eu"]
"colors": {
"primaryColor": "#b8cf5b"
},
"defaultLocale": "en",
"logo": "/logo.svg"
}
74 changes: 37 additions & 37 deletions config/discoveryConfig.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
/**
* Configuration options for the Discovery website.
*/
export interface DiscoveryConfig {
/**
* The default locale for the website. The locales have to be provided and present to be applied.
*/
defaultLocale: string;
import { z } from "zod";
import userConfig from "./discoveryConfig.json";
const locales = ["en", "de"] as const;

const schema = z.object({
/**
* The custom format for displaying dates and times on the Discovery website.
* The title of the website.
* Specifies the title that will be used for the Discovery website.
* @default OpenAtlas Discovery
*/
dateTimeFormat?: string;
title: z.string().default("OpenAtlas Discovery"),

/**
* A list of filters represented as numbers.
* Acts as a whitelist to allow only entities belonging to a certain type given by ID.
* These filters are applied in the Overview and Search sections of the website but not in the detailed view.
* The description of the website.
* Specifies the description that will be used for the Discovery website.
*/
defaultFilters?: number[];
description: z.string().optional(),

/**
* The base URL for the Discovery website's API.
* If provided, it specifies the root URL that will be used for making API requests.
* The default locale for the website. The locales have to be provided and present to be applied.
*/
APIbase?: string;
defaultLocale: z.enum(locales).default("en"),

/**
* The list of allowed image domains.
* Specifies the domains from which images can be optimized via nuxt-img for the Discovery website.
* A list of filters represented as numbers.
* Acts as a whitelist to allow only entities belonging to a certain type given by ID.
* These filters are applied in the Overview and Search sections of the website but not in the detailed view.
*/
imageDomains?: string[];
defaultFilters: z.array(z.number()).optional(), // should be required

/**
* Hex color code for the primary color of the website.
*/
primaryColor?: string;
colors: z.object({
/**
* Hex color code for the primary color of the website.
*/
primaryColor: z.string().default("#b8cf5b"),

/**
* Hex color for the secondary color of the website
*/
secondaryColor: z.string().optional(),
}),

/**
* Logo
* Specifies the logo that will be used for the Discovery website.
* @default logo.svg
*/
logo: string;
logo: z.string().default("logo.svg"),

/**
* Header Logo
* Specifies the logo that will be used for the header of the Discovery website. Will default to logo if not provided.
* @default logo
* @see logo
*/
headerLogo?: string;

// Favicon
headerLogo: z.string().optional(), // should be required

/**
* The favicon of the website.
* Specifies the favicon that will be used for the Discovery website.
* @supportedTypes image/svg+xml, image/x-icon
*/
favicon?: string;
favicon: z.string().optional(), // should be required
});

/**
* The title of the website.
* Specifies the title that will be used for the Discovery website.
* @default OpenAtlas Discovery
*/
title: string;
const result = schema.safeParse(userConfig);
if (!result.success) {
console.error("invalid config!", result.error.flatten().fieldErrors);
throw new Error("invalid config!");
}

export const defaultDiscoveryConfig: DiscoveryConfig = {
defaultLocale: "en",
logo: "/logo.svg",
title: "OpenAtlas Discovery",
};
export const discoveryConfig = result.data;
5 changes: 5 additions & 0 deletions content/de/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
title: Home
navigation:
title: OpenAtlas Discovery
---
![logo](/OpenAtlasDiscovery_logo.jpg)

# OpenAtlas Discovery
Expand Down
3 changes: 2 additions & 1 deletion content/en/about.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: About
navigation:
title: "About"
title: About
---

# About
Expand Down
5 changes: 5 additions & 0 deletions content/en/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
title: Home
navigation:
title: OpenAtlas Disovery
---
![logo](/logo.svg)

# OpenAtlas Discovery
Expand Down
4 changes: 2 additions & 2 deletions deployment/loadContent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from "fs-extra";

const clonedContentPath = "temp";

// from env variable or argument or default value
// from .env variable or argument or default value
const repo =
process.env.CONTENT_REPO ?? process.argv[2] ?? "acdh-oeaw/OpenAtlas-Discovery-Content-Template";
const branch = process.env.CONTENT_BRANCH ?? process.argv[3] ?? "main";
Expand Down Expand Up @@ -40,7 +40,7 @@ if (fs.existsSync(clonedContentPath)) {
*/
function cloneRepo(targetpath, repo, branch, useHttp = true) {
// From https://cheatcode.co/tutorials/how-to-clone-and-sync-a-github-repo-via-node-js
// child_process.execSync(`git clone ${getBranch(branch)} https://${username}:${process.env.PERSONAL_ACCESS_TOKEN}@github.com/${username}/${repo}.git ${targetpath}`);
// child_process.execSync(`git clone ${getBranch(branch)} https://${username}:${process..env.PERSONAL_ACCESS_TOKEN}@github.com/${username}/${repo}.git ${targetpath}`);

if (fs.existsSync(targetpath)) {
fs.rmSync(clonedContentPath, { recursive: true, force: true });
Expand Down
3 changes: 2 additions & 1 deletion locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"end to": "Ende bis",
"realation to id": "Beziehung-ID",
"id": "ID"
}
},
"imprint": "Impressum"
},
"components": {
"entity": {
Expand Down
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"end to": "end to",
"realation to id": "realation to id",
"id": "id"
}
},
"imprint": "Imprint"
},
"components": {
"entity": {
Expand Down
3 changes: 1 addition & 2 deletions middleware/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export default defineNuxtRouteMiddleware(() => {
const { $discoveryConfig } = useNuxtApp();
if ($discoveryConfig.APIbase === undefined) {
if (useRuntimeConfig().public.APIBase === undefined) {
return navigateTo("/", { redirectCode: 308 });
}
});
7 changes: 3 additions & 4 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { execSync } from "node:child_process";
import { DiscoveryConfig } from "./config/discoveryConfig";
import discoveryConfig from "./config/discoveryConfig.json";
const config: DiscoveryConfig = discoveryConfig as DiscoveryConfig;
const branchName = execSync("git rev-parse --abbrev-ref HEAD").toString().trimEnd();
const commitHash = execSync("git rev-parse HEAD").toString().trimEnd();
const gitTag = execSync("git describe --always --tags").toString().trimEnd();
Expand All @@ -15,14 +13,15 @@ export default defineNuxtConfig({
head: {
meta: [
{
name: config.title ?? "OpenAtlas Discovery",
name: discoveryConfig.title,
},
],
},
},
runtimeConfig: {
// Keys within public, will be also exposed to the client-side
public: {
APIBase: process.env.NUXT_PUBLIC_API_BASE_URL,
commitHash,
branchName,
gitTag,
Expand Down Expand Up @@ -72,7 +71,7 @@ export default defineNuxtConfig({
},
},
image: {
domains: config.imageDomains ?? ["openatlas.eu"],
domains: JSON.parse(process.env.NUXT_PUBLIC_IMAGE_DOMAINS),
inject: true,
},
});
Loading

0 comments on commit 8565bc6

Please sign in to comment.