Skip to content

Commit

Permalink
Add host handle for public page
Browse files Browse the repository at this point in the history
  • Loading branch information
VovaStelmashchuk committed Aug 21, 2024
1 parent afb022d commit 78ac596
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 66 deletions.
4 changes: 2 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const init = async () => {
server.views({
engines: { html: Handlebars },
relativeTo: __dirname,
partialsPath: 'templates/partials',
path: ['templates/pages', 'templates/partials'],
partialsPath: ['templates/partials', 'templates/widgets'],
path: ['templates/pages', 'templates/partials', 'templates/widgets'],
layout: true,
layoutPath: 'templates/layouts',
});
Expand Down
4 changes: 4 additions & 0 deletions src/core/episodeRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export function updateMontageStatusBySlug(slug, status) {
return Database.collection('posts').updateOne({ slug: slug }, { $set: { montage_status: status } });
}

export function updateMontageStatusToSuccessBySlug(slug, audioFileKey) {
return Database.collection('posts').updateOne({ slug: slug }, { $set: { montage_status: 'success', audio_file_key: audioFileKey } });
}

export function publishPodcast(slug) {
return Database.collection('posts').updateOne({ slug: slug }, { $set: { visibility: 'public' } });
}
Expand Down
7 changes: 7 additions & 0 deletions src/core/podcastRepo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Database } from "./client.js";

export async function getShowInfo(podcastDomain) {
return Database.collection('shows').findOne({ domains: podcastDomain });
}


4 changes: 2 additions & 2 deletions src/montage/publicAudioGenerator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { updateMontageStatusBySlug } from '../core/episodeRepo.js';
import { updateMontageStatusBySlug, updateMontageStatusToSuccessBySlug } from '../core/episodeRepo.js';
import { applyFFmpegToFileInMinio } from '../minio/ffmpegApply.js';

async function createPublicAudioJob(podcast) {
Expand Down Expand Up @@ -42,7 +42,7 @@ export async function createPublicAudio(podcast) {

createPublicAudioJob(podcast)
.then(async () => {
await modifyPodcastStatus(podcast.slug, 'success');
await updateMontageStatusToSuccessBySlug(podcast.slug, `episodes/${podcast.slug}.mp3`);
console.log('Public audio creation successful.');
})
.catch(async (error) => {
Expand Down
6 changes: 6 additions & 0 deletions src/routers/details.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { getPostBySlug } from "../core/episodeRepo.js";
import { buildObjectURL } from "../minio/utils.js";
import { buildPublicChapters } from "../core/generator.js";
import { getShowInfo } from "../core/podcastRepo.js";

async function podcastDetailsHandler(request, h) {
const host = request.headers.host;
const showInfo = await getShowInfo(host)

const slug = request.params.slug;
const preview = request.query.preview;

Expand All @@ -14,6 +18,8 @@ async function podcastDetailsHandler(request, h) {

return h.view('podcastDetails',
{
showName: showInfo.showName,
header_links: showInfo.links,
title: podcast.title,
audioUrl: buildObjectURL('episodes/' + podcast.audio_file_key),
chapters: publicChapters
Expand Down
29 changes: 20 additions & 9 deletions src/routers/home.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { getPublicPosts } from "../core/episodeRepo.js";
import { getShowInfo } from "../core/podcastRepo.js";

async function homeHandler(request, h) {
return h.view('home', {}, { layout: 'layout' });
const host = request.headers.host;
const showInfo = await getShowInfo(host)

return h.view('home', {
showName: showInfo.showName,
header_links: showInfo.links,
}, {
layout: 'layout'
});
}

async function podcastListHandler(request, h) {
const posts = await getPublicPosts();
const postsWithChartersDescription = posts.map(post => ({
...post,
chartersDescription: post.charters ? post.charters.map(charter => charter.description).join(' ') : '',
chartersDescription: post.charters ? post.charters.map(charter => charter.description).join(' ') : '',
url: post.type === 'public' ? `/podcast/${post.slug}` : 'https://www.patreon.com/androidstory',
}));

Expand All @@ -20,13 +29,15 @@ async function podcastListHandler(request, h) {
);
}

function aboutHandler(request, h) {
const html = `
<div id="tab-content" role="tabpanel" class="tab-content">
<p class="text-xl">Двa андроїдщики, два Вови і деколи дві різні думки. Кожний подкаст ми обговорюємо нові релізи в світі android розробки, кращі і не дуже практики. Ділимося своїми думками, досвідом і деколи пробуємо не смішно жатрувати. Також тут ви знайдете рекомендації початківцям, а хто давно в розробці мають тут просто гарно провести час.</p>
</div>
`;
return h.response(html).type('text/html');
async function aboutHandler(request, h) {
const host = request.headers.host;
const show = await getShowInfo(host)

return h.view('about', {
about: show.about,
}, {
layout: false
});
}

export function home(server) {
Expand Down
2 changes: 1 addition & 1 deletion src/templates/layouts/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Android story podcast</title>
<title>{{showName}}</title>
<link href="/public/styles.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]"></script>
</head>
Expand Down
47 changes: 23 additions & 24 deletions src/templates/pages/home.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
<div class="flex justify-center">
<div id="tabs" hx-target="#tab-contents" role="tablist">
<button role="tab" aria-controls="tab-contents" aria-selected="true" hx-get="/tab-podcast-list"
class="px-4 py-2 font-semibold text-black bg-gray-200 rounded-t-md focus:outline-none selected">
Podcasts
</button>
<button role="tab" aria-controls="tab-contents" aria-selected="false" hx-get="/tab-about"
class="px-4 py-2 font-semibold text-black bg-gray-200 rounded-t-md focus:outline-none">
About
</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('tabs').addEventListener('click', function (event) {
if (event.target.tagName !== 'BUTTON') return
let currentTab = document.querySelector('[aria-selected=true]');
currentTab.setAttribute('aria-selected', 'false')
currentTab.classList.remove('selected')
let newTab = event.target
newTab.setAttribute('aria-selected', 'true')
newTab.classList.add('selected')
})
<div id="tabs" hx-target="#tab-contents" role="tablist">
<button role="tab" aria-controls="tab-contents" aria-selected="true" hx-get="/tab-podcast-list"
class="px-4 py-2 font-semibold text-black bg-gray-200 rounded-t-md focus:outline-none selected">
Podcasts
</button>
<button role="tab" aria-controls="tab-contents" aria-selected="false" hx-get="/tab-about"
class="px-4 py-2 font-semibold text-black bg-gray-200 rounded-t-md focus:outline-none">
About
</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('tabs').addEventListener('click', function (event) {
if (event.target.tagName !== 'BUTTON') return
let currentTab = document.querySelector('[aria-selected=true]');
currentTab.setAttribute('aria-selected', 'false')
currentTab.classList.remove('selected')
let newTab = event.target
newTab.setAttribute('aria-selected', 'true')
newTab.classList.add('selected')
})
</script>
})
</script>
</div>
<div id="tab-contents" role="tabpanel" hx-get="/tab-podcast-list" hx-trigger="load"
class="p-4">
<div id="tab-contents" role="tabpanel" hx-get="/tab-podcast-list" hx-trigger="load" class="p-4">
</div>
10 changes: 5 additions & 5 deletions src/templates/partials/buttons/build_audio.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<button hx-swap="outerHTML" hx-post="/admin/podcast/{{slug}}/update-files"
class="common-button w-full px-4 py-2 my-2 transition-all duration-300 ease-in-out" {{#if
isAudioBuildInProgress}}disabled{{/if}}>
Build audio files
</button>
<button hx-swap="outerHTML" hx-post="/admin/podcast/{{slug}}/update-files"
class="common-button w-full px-4 py-2 my-2 transition-all duration-300 ease-in-out" {{#if
isAudioBuildInProgress}}disabled{{/if}}>
Build audio files
</button>
5 changes: 2 additions & 3 deletions src/templates/partials/editable_time_code.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<input value="{{description}}" type="text" name="text" placeholder="Description"
hx-trigger="keyup changed delay:500ms" hx-put="/admin/podcast/{{slug}}/timecodes/{{index}}" hx-swap="none"
hx-include="closest .timecode-entry" class="flex-1 px-2 py-1 border focus:border-black rounded">
<input type="checkbox" name="isPublic" class="w-5 h-5" {{#if isPublic}}checked{{/if}}
hx-trigger="change" hx-put="/admin/podcast/{{slug}}/timecodes/{{index}}" hx-swap="none"
hx-include="closest .timecode-entry">
<input type="checkbox" name="isPublic" class="w-5 h-5" {{#if isPublic}}checked{{/if}} hx-trigger="change"
hx-put="/admin/podcast/{{slug}}/timecodes/{{index}}" hx-swap="none" hx-include="closest .timecode-entry">
</div>
25 changes: 5 additions & 20 deletions src/templates/partials/head.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
<div>
<div class="bg-gray-200 p-6 rounded-lg mb-8 text-center cursor-pointer" id="header">
<h1 class="text-3xl md:text-4xl font-bold mb-4">Android Story Podcast</h1>
<h1 class="text-3xl md:text-4xl font-bold mb-4">{{showName}}</h1>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 container max-w-screen-xl mx-auto">
<a href="https://androidstory.dev/files/rss.xml">
<button class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded w-full">
Наш RSS тут
</button>
</a>
<a href="https://open.spotify.com/show/4DzbFWyfcFX5zzh6MicCfM?si=99dda8490dd942c7">
<button class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded w-full">
Spotify для патреонів
</button>
</a>
<a href="https://www.patreon.com/androidstory">
<button class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded w-full">
Більше цікавого тут
</button>
</a>
<a href="https://www.youtube.com/channel/UC6-NFk4uOGsKvyisL1QC3rw">
<button class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded w-full">
YouTube
</button>
{{#each header_links}}
<a href="{{link}}">
<button class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded w-full">{{text}}</button>
</a>
{{/each}}
</div>
</div>
<script>
Expand Down
3 changes: 3 additions & 0 deletions src/templates/widgets/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="tab-content" role="tabpanel" class="tab-content">
<p class="text-xl">{{about}}</p>
</div>

0 comments on commit 78ac596

Please sign in to comment.