Skip to content

Commit

Permalink
external menu feature
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexRoehm committed Aug 9, 2024
1 parent 8919fba commit 5469249
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 121 deletions.
11 changes: 0 additions & 11 deletions backend/data/files/menu-ext-de.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
{
"settings": {
"baseUrl": "http://localhost:3000",
"defaultRoute": "/recent",
"menuSource": "",
"skin": "",
"logo": "/img/logo.png",
"logo_w": "/img/logo-w.png",
"enableDarkOption": false,
"closeOnScroll": false,
"nondefault": false
},
"menu": [
{
"Description": "Höre unsere Predigen, Inputs und Biblestudies oder lies Neues und Andachten",
Expand Down
11 changes: 0 additions & 11 deletions backend/data/files/meta-de.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
{
"settings": {
"baseUrl": "http://localhost:3000",
"defaultRoute": "/recent",
"menuSource": "",
"skin": "",
"logo": "/img/logo.png",
"logo_w": "/img/logo-w.png",
"enableDarkOption": false,
"closeOnScroll": false,
"nondefault": false
},
"menu": [{
"Description": "Höre aktuelle und zuletzt erschienene Folgen",
"Name": "Hör rein",
Expand Down
11 changes: 0 additions & 11 deletions backend/data/files/meta-en.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
{
"settings": {
"baseUrl": "http://localhost:3000",
"defaultRoute": "/recent",
"menuSource": "",
"skin": "",
"logo": "/img/logo.png",
"logo_w": "/img/logo-w.png",
"enableDarkOption": false,
"closeOnScroll": false,
"nondefault": false
},
"menu": [
{
"Description": "Listen to our content",
Expand Down
37 changes: 34 additions & 3 deletions backend/src/controller/Settings.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
import * as fs from 'fs';
import { Request, Response } from "express";
import { DATABASE_PATH, DATAFILES_PATH } from "../tools/Configuration";
import { DATABASE_PATH, DATAFILES_PATH, EXT_MENU_AP, EXT_MENU_FILTER, EXT_MENU_BASEURL } from "../tools/Configuration";
import { sendResponse } from '../tools/Controller';
import { Any, EntityMetadata } from 'typeorm';

var menu = []

function linkGenerator( section: any ) : any {
const linker = item => {
if (!item.link || item.link.length <1)
if (item.page && item.page.slug && item.page.slug.length > 0)
item.link = EXT_MENU_BASEURL + item.page.slug
}
linker(section)
section.menu_items.forEach(element => linker(element));
return section
}

async function getExternalMenu( locale: string ) : Promise<any> {
if (!EXT_MENU_AP.startsWith('http')) return []
const url = EXT_MENU_AP.replace("locale",locale)
const result = await fetch(url)
const ext_menu = await result.json() as Array<any>
return ext_menu.filter(( item: any ) => !item.link || item.link.toLowerCase().indexOf(EXT_MENU_FILTER?.toLowerCase()) === -1).map(linkGenerator)
}
async function getLocalMenu( locale: string ) : Promise<any> {
const meta = JSON.parse(fs.readFileSync(DATABASE_PATH + DATAFILES_PATH + 'meta-'+locale+'.json',{encoding:'utf8', flag:'r'}));
console.log(EntityMetadata)
return meta.menu
}

export async function getMetadata(request: Request, response: Response) {
const locale = request.query.locale
const meta = JSON.parse(fs.readFileSync(DATABASE_PATH + DATAFILES_PATH + 'meta-'+locale+'.json',{encoding:'utf8', flag:'r'}));
sendResponse( response, meta)
if (menu.length<1) {
const ext_menu = await getExternalMenu(locale as string)
const loc_menu = await getLocalMenu(locale as string)
menu = ext_menu.concat(loc_menu)
}
sendResponse( response, { menu })
}
3 changes: 3 additions & 0 deletions backend/src/tools/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ require('dotenv').config()
export const DATABASE_PATH = process.env.DATABASE_PATH ?? 'data';
export const DATA_PATH = process.env.DATA_PATH ?? 'public';
export const DATABASE_FILE = process.env.DATABASE_FILE ?? "podcasts.sqlite"
export const EXT_MENU_AP = process.env.EXT_MENU_AP ?? ""
export const EXT_MENU_FILTER = process.env.EXT_MENU_FILTER ?? ""
export const EXT_MENU_BASEURL = process.env.EXT_MENU_BASEURL ?? ""
export const DATAFILES_PATH = '/files/'
export const SERVER_IMG_PATH = '/s/covers/';
export const SERVER_POSTIMG_PATH = '/s/posts/';
Expand Down
1 change: 0 additions & 1 deletion base/RssGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Podcast } from 'podcast';
import { useSettings } from '~~/composables/settingsdata';
import { FEED_SLUG, SERVER_IMG_PATH, SERVER_MP3_PATH } from './Constants';
import { ContentFile } from './ContentFile';
import IPodcast from './types/IPodcast';
Expand Down
3 changes: 1 addition & 2 deletions components/Page/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default defineComponent({
},
async setup(props, ctx) {
const { locale } = useI18n();
const { menu, settings, loading } = useMetaData(locale.value, true);
const { menu, loading } = useMetaData(locale.value, true);
const { user } = useAuth();
const showMenu = ref(false);
Expand Down Expand Up @@ -114,7 +114,6 @@ onMounted(() => {
showMenu,
logo,
menu,
settings,
loading,
user
}
Expand Down
60 changes: 1 addition & 59 deletions composables/useMetaData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const menu = ref(undefined)
const settings = ref(undefined)

export default function useMetaData(locale: string, load = true) {
const {apiBase} = useRuntimeConfig().public
Expand All @@ -11,71 +10,14 @@ export default function useMetaData(locale: string, load = true) {
.then(response => response.json())
.then(response => {
menu.value = response.menu
settings.value = response.settings
loading.value = false
})
}
if (!menu.value && load)
refresh()
return {
menu,
settings,
loading,
refresh
}
}

// export interface ISettings {
// baseUrl: string
// defaultRoute: string
// menuSource: string
// skin: string
// logo: string
// logo_w: string
// enableDarkOption: boolean,
// nondefault: boolean
// }

// export async function useMetaData(locale: string) : Promise<{ccf: Ref<any>, menu: Ref<any>, settings: Ref<any>}> {
// const { apiBase } = useRuntimeConfig().public
// const result = await $fetch( apiBase+ 'meta?locale=' + locale )
// const menu = ref(result?result.menu:[])
// const ccf = ref(result?result.settings:[])

// const settings = ref({
// baseUrl: "http://localhost:3000",
// defaultRoute: "/recent",
// menuSource: "",
// skin: "",
// logo: "/img/logo.png",
// logo_w: "/img/logo-w.png",
// enableDarkOption: false,
// closeOnScroll: false,
// nondefault: false
// } as ISettings)
// return { ccf, menu, settings }
// }

// async function getSettings() {
// const { apiBase } = useRuntimeConfig().public
// const settings = ref()
// if (!settings.value.nondefault) {
// const set = await $fetch( apiBase + "/settings") as Partial<ISettings>
// settings.value.nondefault = true
// if (set.baseUrl)
// settings.value.baseUrl = set.baseUrl
// if (set.defaultRoute)
// settings.value.defaultRoute = set.defaultRoute
// if (set.menuSource)
// settings.value.menuSource = set.menuSource
// if (set.enableDarkOption)
// settings.value.enableDarkOption = set.enableDarkOption
// if (set.skin)
// settings.value.skin = set.skin
// if (set.logo)
// settings.value.logo = set.logo
// if (set.logo_w)
// settings.value.logo_w = set.logo_w
// }
// return settings
// }
}
11 changes: 0 additions & 11 deletions cypress/fixtures/meta-de.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
{
"settings": {
"baseUrl": "http://localhost:3000",
"defaultRoute": "/recent",
"menuSource": "",
"skin": "",
"logo": "/img/logo.png",
"logo_w": "/img/logo-w.png",
"enableDarkOption": false,
"closeOnScroll": false,
"nondefault": false
},
"menu": [{
"Description": "Höre aktuelle und zuletzt erschienene Folgen",
"Name": "Hör rein",
Expand Down
11 changes: 0 additions & 11 deletions cypress/fixtures/meta-en.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
{
"settings": {
"baseUrl": "http://localhost:3000",
"defaultRoute": "/recent",
"menuSource": "",
"skin": "",
"logo": "/img/logo.png",
"logo_w": "/img/logo-w.png",
"enableDarkOption": false,
"closeOnScroll": false,
"nondefault": false
},
"menu": [
{
"Description": "Listen to our content",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"dev:be": "cd backend; yarn dev",
"dev:cy": "npx cypress open --env NUXT_MODE=development",
"run:cy": "npx cypress run --env NUXT_MODE=development",
"rec:cy": "npx cypress run --record --key 6b81c56a-4e73-4cfd-a36d-acab9f138d57 --env NUXT_MODE=development"
"rec:cy": "npx cypress run --record --key 6b81c56a-4e73-4cfd-a36d-acab9f138d57 --env NUXT_MODE=development",
"clean:cy": "rm -r ./backend/public/s && rm ./backend/data/podcasts.sqlite"
},
"devDependencies": {
"@nuxtjs/color-mode": "^3.4.2",
Expand Down

0 comments on commit 5469249

Please sign in to comment.