Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base
layout :set_layout

before_action :configure_permitted_parameters, if: :devise_controller?
before_action :set_default_meta_tags

inertia_share categories: -> {
Category.includes(:topics).all.as_json(methods: :topics_count)
Expand Down Expand Up @@ -42,4 +43,15 @@ def configure_permitted_parameters

devise_parameter_sanitizer.permit(:account_update, keys: [ :username ])
end

def set_default_meta_tags
inertia_meta.add([
{ title: "Pups & Pourovers" },
{ name: "description", content: "Online home of the overcaffeinated dog enthusiast" },
{ name: "viewport", content: "width=device-width,initial-scale=1" },
{ name: "apple-mobile-web-app-capable", content: "yes" },
{ name: "mobile-web-app-capable", content: "yes" },
{ name: "application-name", content: "Pups & Pourovers" }
])
end
end
5 changes: 4 additions & 1 deletion app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ def show
topics: { include: [ :user, :category, messages: { include: :user } ] }
])

render inertia: { category: }
render inertia: { category: }, meta: [
{ title: "Category: #{category["name"]} - Pups & Pourovers" },
{ name: "description", content: "Browse topics in the #{category["name"]} category on Pups & Pourovers" }
]
end
end
6 changes: 5 additions & 1 deletion app/controllers/my_topics_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class MyTopicsController < ApplicationController
before_action :verify_user

def index
topics = Topic.includes(:user, :category, messages: :user)
.joins(:messages)
Expand All @@ -13,7 +14,10 @@ def index
messages: { include: :user }
])

render inertia: { topics: }
render inertia: { topics: }, meta: [
{ title: "My Topics - Pups & Pourovers" },
{ name: "description", content: "View your topics on Pups & Pourovers" }
]
end

private
Expand Down
10 changes: 8 additions & 2 deletions app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ def index
messages: { include: :user }
])

render inertia: { topics: }
render inertia: { topics: }, meta: [
{ title: "Topics - Pups & Pourovers" },
{ name: "description", content: "Browse topics on Pups & Pourovers" }
]
end

def show
Expand All @@ -21,6 +24,9 @@ def show
:category,
messages: { include: :user }
])
render inertia: { topic: }
render inertia: { topic: }, meta: [
{ title: "#{topic["title"]} - Pups & Pourovers" },
{ name: "description", content: "#{topic["title"]} - Pups & Pourovers" }
]
end
end
34 changes: 34 additions & 0 deletions app/frontend/components/MetaTags.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'
import { Head, usePage } from '@inertiajs/react'
import { Meta } from '../types'

const MetaTags = () => {
const { _inertia_meta: meta } = usePage<{ _inertia_meta: Meta[] }>().props
return (
<Head>
{meta.map((meta: Meta) => {
const { tagName, innerContent, headKey, httpEquiv, ...attrs } = meta

let stringifiedInnerContent
if (innerContent != null) {
stringifiedInnerContent =
typeof innerContent === 'string'
? innerContent
: JSON.stringify(innerContent)
}

return React.createElement(tagName, {
key: headKey,
'head-key': headKey,
...(httpEquiv ? { 'http-equiv': httpEquiv } : {}),
...attrs,
...(stringifiedInnerContent
? { dangerouslySetInnerHTML: { __html: stringifiedInnerContent } }
: {}),
})
})}
</Head>
)
}

export default MetaTags
2 changes: 2 additions & 0 deletions app/frontend/layouts/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@heroicons/react/24/outline'
import { User } from '@/types'
import Sidebar from "@/components/Sidebar";
import MetaTags from '../components/MetaTags'

interface AppLayoutProps {
children: ReactNode
Expand All @@ -21,6 +22,7 @@ export default function AppLayout({ children }: AppLayoutProps) {

return (
<div className="flex h-screen bg-gray-50">
<MetaTags />
<Sidebar isOpen={sidebarOpen} />

<div className="flex-1 flex flex-col overflow-hidden">
Expand Down
2 changes: 2 additions & 0 deletions app/frontend/pages/landing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { Menu, MenuButton, MenuItems, MenuItem } from '@headlessui/react'
import { ChevronDownIcon } from '@heroicons/react/24/outline'
import { Category, User } from '../../types'
import Luna from '../../assets/luna.gif'
import MetaTags from '../../components/MetaTags'

export default function LandingIndex() {
const { props: { categories, current_user: currentUser } } = usePage<{ categories: Category[], current_user: User }>();

return (
<>
<MetaTags />
<nav className="fixed top-0 left-0 right-0 z-50 bg-white/80 backdrop-blur-md border-b border-gray-200/50">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-16">
Expand Down
3 changes: 0 additions & 3 deletions app/frontend/pages/my_topics/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Head } from '@inertiajs/react'
import AppLayout from '../../layouts/AppLayout'
import { Topic } from '../../types'
import TopicsTable from '../../components/TopicsTable'

function MyTopicsIndex({ topics }: { topics: Topic[] }) {
return (
<AppLayout>
<Head title="My Topics - Pups & Pourovers" />

<div className="max-w-7xl mx-auto">
<div className="bg-white shadow-sm rounded-lg overflow-hidden">
<TopicsTable topics={topics} />
Expand Down
3 changes: 0 additions & 3 deletions app/frontend/pages/topics/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Head } from '@inertiajs/react'
import AppLayout from '../../layouts/AppLayout'
import { Topic } from '../../types'
import TopicsTable from '../../components/TopicsTable'

function TopicsIndex({ topics }: { topics: Topic[] }) {
return (
<AppLayout>
<Head title="Topics - Pups & Pourovers" />

<div className="max-w-7xl mx-auto">
<div className="bg-white shadow-sm rounded-lg overflow-hidden">
<TopicsTable topics={topics} />
Expand Down
4 changes: 1 addition & 3 deletions app/frontend/pages/topics/show.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Head, Form } from '@inertiajs/react'
import { Form } from '@inertiajs/react'
import AppLayout from '../../layouts/AppLayout'
import { Topic, Message, User } from '../../types'
import LexicalRichTextEditor from '../../components/LexicalRichTextEditor'
Expand Down Expand Up @@ -49,8 +49,6 @@ function TopicsShow({ topic, current_user: currentUser }: { topic: Topic, curren

return (
<AppLayout>
<Head title={`${title} - Pups & Pourovers`} />

<div className="max-w-4xl mx-auto">
<div className="bg-white rounded-lg shadow-sm border border-gray-200 p-6 mb-6">
<div className="flex items-start justify-between">
Expand Down
7 changes: 2 additions & 5 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<title inertia><%= content_for(:title) || "Inertia Workshop Advanced Demo" %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="application-name" content="Inertia Workshop Advanced Demo">
<meta name="mobile-web-app-capable" content="yes">
<%= inertia_meta_tags %>

<%= csrf_meta_tags %>
<%= csp_meta_tag %>

Expand Down