Skip to content

Commit

Permalink
Merge pull request #263 from openzim/configure-ui-colors
Browse files Browse the repository at this point in the history
Add support for color CLI arguments in new UI
  • Loading branch information
benoit74 authored Jul 11, 2024
2 parents 67d2a6c + 35c4e76 commit aaa6b0a
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 16 deletions.
7 changes: 7 additions & 0 deletions scraper/src/youtube2zim/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,10 @@ class Channel(CamelModel):
joined_date: str
collection_type: str
main_playlist: str | None = None


class Config(CamelModel):
"""Class to serialize configuration data for the ZIM UI."""

main_color: str | None
secondary_color: str | None
12 changes: 12 additions & 0 deletions scraper/src/youtube2zim/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from youtube2zim.schemas import (
Author,
Channel,
Config,
Playlist,
PlaylistPreview,
Playlists,
Expand Down Expand Up @@ -1182,6 +1183,17 @@ def get_playlist_slug(playlist) -> str:
is_front=False,
)

# write config.json file
self.zim_file.add_item_for(
path="config.json",
title="Config",
content=Config(
main_color=self.main_color, secondary_color=self.secondary_color
).model_dump_json(by_alias=True, indent=2),
mimetype="application/json",
is_front=False,
)

# clean videos left out in videos directory
remove_unused_videos(videos)

Expand Down
Binary file removed zimui/src/assets/images/banner-placeholder.jpg
Binary file not shown.
14 changes: 11 additions & 3 deletions zimui/src/components/channel/ChannelHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import AboutDialogButton from '@/components/channel/AboutDialogButton.vue'
import { useMainStore } from '@/stores/main'
import profilePlaceholder from '@/assets/images/profile-placeholder.jpg'
import bannerPlaceholder from '@/assets/images/banner-placeholder.jpg'
const { mdAndDown } = useDisplay()
Expand Down Expand Up @@ -43,8 +42,7 @@ const tab = ref<number>(tabs[0].id)
<v-parallax
:scale="1"
height="120"
class="rounded-lg rounded-t-0"
:lazy-src="bannerPlaceholder"
class="banner-bg rounded-lg rounded-t-0"
:src="main.channel?.bannerPath"
></v-parallax>

Expand Down Expand Up @@ -97,4 +95,14 @@ const tab = ref<number>(tabs[0].id)
border-top-right-radius: 0 !important;
}
}
.banner-bg {
background: rgb(var(--v-theme-primary));
background: linear-gradient(
120deg,
rgba(var(--v-theme-primary-darken-1)) 0%,
rgba(var(--v-theme-primary)) 50%,
rgba(var(--v-theme-primary-lighten-1)) 100%
);
}
</style>
2 changes: 1 addition & 1 deletion zimui/src/components/playlist/panel/PlaylistPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const emit = defineEmits(['shuffle', 'loop', 'hide-panel'])

<template>
<v-card class="border-thin rounded-lg" flat>
<v-card-item class="border-b-thin bg-grey-lighten-5 px-2">
<v-card-item class="border-b-thin px-2">
<v-row class="px-2">
<v-col :cols="showToggle ? 9 : 12">
<v-card-title class="panel-title">{{ props.playlist.title }}</v-card-title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const emit = defineEmits(['click'])

<template>
<v-card
class="mx-auto border-thin rounded-lg"
class="mx-auto border-thin rounded-lg bg-background-darken-1"
prepend-icon="mdi-playlist-play"
append-icon="mdi-chevron-down"
link
Expand Down
20 changes: 12 additions & 8 deletions zimui/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'
import vuetify from './plugins/vuetify'
import loadVuetify from './plugins/vuetify'

const app = createApp(App)

app.use(createPinia())
app.use(vuetify)
app.use(router)

app.mount('#app')
loadVuetify()
.then((vuetify) => {
const app = createApp(App)
app.use(createPinia())
app.use(vuetify)
app.use(router)
app.mount('#app')
})
.catch((error) => {
console.error('Error initializing app:', error)
})
44 changes: 43 additions & 1 deletion zimui/src/plugins/vuetify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
import 'vuetify/styles'
import '@mdi/font/css/materialdesignicons.css'
import { createVuetify } from 'vuetify'
import type { Config } from '@/types/Channel'

export default createVuetify()
async function loadVuetify() {
let primaryColor = '#000000'
let secondaryColor = '#FFFFFF'

// Load primary and secondary colors from config.json
try {
const response = await fetch('./config.json')
if (response.ok) {
const config: Config = await response.json()
primaryColor = config.mainColor || primaryColor
secondaryColor = config.secondaryColor || secondaryColor
} else {
console.error('Failed to fetch config.json')
}
} catch (error) {
console.error('Error loading config:', error)
}

const zimuiTheme = {
colors: {
background: secondaryColor,
surface: secondaryColor,
primary: primaryColor
}
}

return createVuetify({
theme: {
defaultTheme: 'zimuiTheme',
variations: {
colors: ['background', 'primary'],
lighten: 2,
darken: 2
},
themes: {
zimuiTheme
}
}
})
}

export default loadVuetify
5 changes: 5 additions & 0 deletions zimui/src/types/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export interface Channel {
mainPlaylist?: string
}

export interface Config {
mainColor: string
secondaryColor: string
}

export interface Author {
channelId: string
channelTitle: string
Expand Down
4 changes: 2 additions & 2 deletions zimui/src/views/PlaylistView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const { mdAndDown } = useDisplay()
<v-row>
<v-spacer />
<v-col cols="12" md="5" lg="4" xl="3" xxl="2">
<v-card flat class="header-card rounded-lg pa-5 bg-grey-lighten-4">
<v-card flat class="header-card rounded-lg border-thin pa-5">
<v-img
:lazy-src="thumbnailPlaceholder"
:src="playlist.thumbnailPath"
Expand Down Expand Up @@ -93,7 +93,7 @@ const { mdAndDown } = useDisplay()
Play All
</v-btn>
<v-btn
class="border-thin bg-grey-lighten-4 flex-fill"
class="border-thin flex-fill"
rounded="lg"
prepend-icon="mdi-shuffle"
variant="flat"
Expand Down

0 comments on commit aaa6b0a

Please sign in to comment.