This commit is contained in:
ct
2025-07-16 19:55:37 +08:00
parent 06675de71b
commit fe32ffda42
12 changed files with 639 additions and 13 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Console\Commands;
use App\Models\MemeMedia;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
class PopulateMemeMediaSlugs extends Command
{
protected $signature = 'memes:populate-slugs';
protected $description = 'Populate slug field for existing MemeMedia records';
public function handle()
{
$this->info('Starting to populate MemeMedia slugs...');
$memes = MemeMedia::whereNull('slug')->get();
if ($memes->isEmpty()) {
$this->info('No memes found without slugs.');
return;
}
$this->info("Found {$memes->count()} memes without slugs.");
$bar = $this->output->createProgressBar($memes->count());
$bar->start();
foreach ($memes as $meme) {
$baseSlug = Str::slug($meme->name);
$slug = $baseSlug;
$counter = 1;
// Ensure slug is unique
while (MemeMedia::where('slug', $slug)->exists()) {
$slug = $baseSlug.'-'.$counter;
$counter++;
}
$meme->update(['slug' => $slug]);
$bar->advance();
}
$bar->finish();
$this->newLine();
$this->info('Successfully populated all MemeMedia slugs!');
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace App\Http\Controllers;
use App\Models\MemeMedia;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
class FrontMemeController extends Controller
{
public function index(Request $request): Response
{
return $this->getMemes($request->input('search'));
}
public function search(string $search): Response
{
// Convert + back to spaces for search
$searchTerm = str_replace('+', ' ', $search);
return $this->getMemes($searchTerm);
}
private function getMemes(?string $search = null): Response
{
$query = MemeMedia::query()
->where('is_enabled', true)
->orderBy('created_at', 'desc');
// Search functionality
if ($search) {
$query->where(function ($q) use ($search) {
$q->where('name', 'ilike', "%{$search}%")
->orWhere('description', 'ilike', "%{$search}%")
->orWhereJsonContains('keywords', $search)
->orWhereJsonContains('action_keywords', $search)
->orWhereJsonContains('emotion_keywords', $search)
->orWhereJsonContains('misc_keywords', $search);
});
}
$memes = $query->paginate(12);
// Get available types for filter
$types = MemeMedia::where('is_enabled', true)
->distinct()
->pluck('type')
->filter();
// Get popular keywords for filter
$popularKeywords = MemeMedia::where('is_enabled', true)
->get()
->pluck('keywords')
->flatten()
->countBy()
->sort()
->reverse()
->take(20)
->keys();
return Inertia::render('memes/index', [
'memes' => $memes,
'types' => $types,
'popularKeywords' => $popularKeywords,
'filters' => [
'search' => $search,
],
]);
}
public function show(string $slug): Response
{
$meme = MemeMedia::where('slug', $slug)
->where('is_enabled', true)
->firstOrFail();
// Get related memes based on similar keywords
$relatedMemes = MemeMedia::where('is_enabled', true)
->where('id', '!=', $meme->id)
->where(function ($query) use ($meme) {
if ($meme->keywords) {
foreach ($meme->keywords as $keyword) {
$query->orWhereJsonContains('keywords', $keyword)
->orWhereJsonContains('action_keywords', $keyword)
->orWhereJsonContains('emotion_keywords', $keyword)
->orWhereJsonContains('misc_keywords', $keyword);
}
}
})
->limit(6)
->get();
return Inertia::render('memes/show', [
'meme' => $meme,
'relatedMemes' => $relatedMemes,
]);
}
}

View File

@@ -53,6 +53,7 @@ class MemeMedia extends Model
'sub_type', 'sub_type',
'original_id', 'original_id',
'name', 'name',
'slug',
'description', 'description',
'keywords', 'keywords',
'group', 'group',

View File

@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('meme_medias', function (Blueprint $table) {
$table->string('slug')->nullable()->after('name');
$table->index('slug');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('meme_medias', function (Blueprint $table) {
$table->dropIndex(['slug']);
$table->dropColumn('slug');
});
}
};

View File

@@ -0,0 +1,24 @@
import { Link } from '@inertiajs/react';
import { route } from 'ziggy-js';
interface KeywordBadgeProps {
keyword: string;
size?: 'default' | 'lg';
className?: string;
}
const sizeClasses = {
default: 'px-2.5 py-0.5 text-xs',
lg: 'px-3 py-1 text-sm',
};
export function KeywordBadge({ keyword, size = 'default', className = '' }: KeywordBadgeProps) {
return (
<Link
href={route('memes.search', keyword.replace(/\s+/g, '+'))}
className={`inline-flex items-center rounded-full border border-transparent bg-secondary text-secondary-foreground font-semibold transition-colors hover:bg-purple-600 hover:text-white focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2 ${sizeClasses[size]} ${className}`}
>
{keyword}
</Link>
);
}

View File

@@ -1,4 +1,4 @@
import { cn } from '@/lib/utils'; import BrandLogo from '@/pages/home/partials/BrandLogo';
import { useMitt } from '@/plugins/MittContext'; import { useMitt } from '@/plugins/MittContext';
import useLocalSettingsStore from '@/stores/localSettingsStore'; import useLocalSettingsStore from '@/stores/localSettingsStore';
@@ -12,14 +12,7 @@ const EditorHeader = ({ className = '', onNavClick = () => {}, isNavActive = fal
}; };
return ( return (
<div className={cn('flex w-full items-center justify-center gap-2', className)}> <BrandLogo></BrandLogo>
<img alt="MEMEFA.ST LOGO" className="h-10 w-10" src="logo/memefast-logo-144.png"></img>
<div className="font-display ml-0 text-lg tracking-wide md:ml-3 md:text-xl">
<span className="text-foreground">MEME</span>
<span className="text-[#00DD00] dark:text-[#00FF00]">FAST</span>
</div>
</div>
// <div className={cn('flex w-full items-center justify-between rounded-xl bg-white p-2 shadow-sm dark:bg-neutral-800', className)}> // <div className={cn('flex w-full items-center justify-between rounded-xl bg-white p-2 shadow-sm dark:bg-neutral-800', className)}>
// <Button onClick={onNavClick} variant="outline" size="icon" className="invisible rounded"> // <Button onClick={onNavClick} variant="outline" size="icon" className="invisible rounded">
// <Menu className="h-8 w-8" /> // <Menu className="h-8 w-8" />

View File

@@ -0,0 +1,18 @@
import { cn } from '@/lib/utils';
import { Link } from '@inertiajs/react';
import { route } from 'ziggy-js';
const BrandLogo = ({ className = '', onNavClick = () => {}, isNavActive = false }) => {
return (
<Link href={route('home')} className={cn('flex w-full items-center justify-center gap-2 hover:opacity-80 transition-opacity', className)}>
<img alt="MEMEFA.ST LOGO" className="h-10 w-10" src="/logo/memefast-logo-144.png"></img>
<div className="font-display ml-0 text-lg tracking-wide md:ml-3 md:text-xl">
<span className="text-foreground">MEME</span>
<span className="text-[#00DD00] dark:text-[#00FF00]">FAST</span>
</div>
</Link>
);
};
export default BrandLogo;

View File

@@ -1,6 +1,7 @@
import { Switch } from '@/components/ui/switch'; import { Switch } from '@/components/ui/switch';
import { useTheme } from '@/hooks/useTheme'; import { useTheme } from '@/hooks/useTheme';
import { Moon, Sun } from 'lucide-react'; import { Moon, Sun } from 'lucide-react';
import { route } from 'ziggy-js';
const Footer = () => { const Footer = () => {
const currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear();
@@ -28,13 +29,16 @@ const Footer = () => {
{/* Navigation Links */} {/* Navigation Links */}
<div className="flex space-x-6"> <div className="flex space-x-6">
<a href="/" className="text-muted-foreground hover:text-foreground text-sm transition-colors"> <a href={route('home')} className="text-muted-foreground hover:text-foreground text-sm transition-colors">
Home Home
</a> </a>
<a href="/terms" className="text-muted-foreground hover:text-foreground text-sm transition-colors"> <a href={route('memes.index')} className="text-muted-foreground hover:text-foreground text-sm transition-colors">
Meme Library
</a>
<a href={route('terms')} className="text-muted-foreground hover:text-foreground text-sm transition-colors">
Terms Terms
</a> </a>
<a href="/privacy" className="text-muted-foreground hover:text-foreground text-sm transition-colors"> <a href={route('privacy')} className="text-muted-foreground hover:text-foreground text-sm transition-colors">
Privacy Privacy
</a> </a>
{import.meta.env.VITE_DISCORD_LINK && ( {import.meta.env.VITE_DISCORD_LINK && (

View File

@@ -0,0 +1,220 @@
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { KeywordBadge } from '@/components/ui/keyword-badge';
import Footer from '@/pages/home/partials/Footer';
import { Link, router } from '@inertiajs/react';
import { Edit, Search } from 'lucide-react';
import { useState } from 'react';
import { route } from 'ziggy-js';
import BrandLogo from '../home/partials/BrandLogo';
interface MemeMedia {
ids: string;
name: string;
description: string;
keywords: string[];
action_keywords: string[];
emotion_keywords: string[];
misc_keywords: string[];
mov_url: string;
webm_url: string;
gif_url: string;
webp_url: string;
slug: string;
}
interface PaginationLinks {
url: string | null;
label: string;
active: boolean;
}
interface PaginatedMemes {
data: MemeMedia[];
current_page: number;
last_page: number;
per_page: number;
total: number;
links: PaginationLinks[];
}
interface Props {
memes: PaginatedMemes;
types: string[];
popularKeywords: string[];
filters: {
search?: string;
};
}
export default function MemesIndex({ memes, popularKeywords, filters }: Props) {
const [search, setSearch] = useState(filters.search || '');
const handleSearch = (e: React.FormEvent) => {
e.preventDefault();
navigateToSearch(search);
};
const handleKeywordClick = (keyword: string) => {
setSearch(keyword);
navigateToSearch(keyword);
};
const navigateToSearch = (searchTerm: string) => {
if (!searchTerm.trim()) {
router.get(route('memes.index'));
return;
}
const trimmedSearch = searchTerm.trim();
// Convert spaces to + for URL segment
const urlSegment = trimmedSearch.replace(/\s+/g, '+');
router.get(route('memes.search', urlSegment));
};
const handlePageChange = (url: string) => {
router.get(url);
};
return (
<>
<div className="min-h-screen bg-neutral-50 pb-10 dark:bg-black">
<div className="container mx-auto px-4 pt-8 pb-0">
<BrandLogo className="py-3"></BrandLogo>
{/* Header */}
<div className="mb-8 text-center">
<h1 className="text-foreground mb-4 text-4xl font-bold">Meme Library</h1>
<p className="text-muted-foreground mx-auto max-w-2xl text-xl">
Thousands of memes ready for TikTok, Reels, Threads and YouTube Shorts. No signup needed - click any meme to start
creating!
</p>
</div>
{/* Search and Filters */}
<Card className="mb-8">
<CardContent className="p-6">
<form onSubmit={handleSearch} className="mb-4 flex flex-col gap-4 md:flex-row">
<div className="flex-1">
<div className="relative">
<Search className="text-muted-foreground absolute top-4 left-4 h-5 w-5" />
<Input
type="text"
placeholder="Search memes..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="h-12 pl-12 text-lg"
/>
</div>
</div>
<Button
type="submit"
size="lg"
className="h-12 bg-gradient-to-r from-purple-600 to-pink-600 text-lg text-white hover:from-purple-700 hover:to-pink-700"
>
Search
</Button>
</form>
{/* Popular Keywords */}
<div className="mt-4">
<h3 className="text-foreground mb-3 text-sm font-medium">Popular Keywords</h3>
<div className="flex flex-wrap gap-2">
{popularKeywords.map((keyword) => (
<KeywordBadge key={keyword} keyword={keyword} size="lg" />
))}
</div>
</div>
{/* Active Search */}
{filters.search && (
<div className="mt-4 flex flex-wrap gap-2">
<Badge variant="secondary" className="flex items-center gap-1">
Search: {filters.search}
<button
onClick={() => {
setSearch('');
router.get(route('memes.index'));
}}
className="ml-1 hover:text-red-500"
>
×
</button>
</Badge>
</div>
)}
</CardContent>
</Card>
{/* Results Count */}
<div className="mb-6 flex items-center justify-between">
<p className="text-muted-foreground">
Showing {memes.data.length} of {memes.total} memes
</p>
</div>
{/* Memes Grid */}
<div className="xs:grid-cols-2 mb-8 grid grid-cols-1 gap-6 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6">
{memes.data.map((meme) => (
<Card key={meme.ids} className="group flex flex-col overflow-hidden p-0 transition-shadow hover:shadow-lg">
<div className="relative aspect-[9/16] overflow-hidden bg-[#00FF00]">
<img
src={meme.webp_url}
alt={meme.name}
className="h-full w-full object-cover transition-transform group-hover:scale-105"
/>
<Link
href={route('memes.show', meme.slug)}
className="bg-opacity-0 absolute inset-0 flex items-center justify-center transition-all group-hover:opacity-40 hover:bg-black"
>
<Edit className="h-8 w-8 text-white opacity-0 transition-opacity group-hover:opacity-100" />
</Link>
</div>
<div className="flex flex-grow flex-col px-4 pt-0 pb-4">
<h3 className="text-foreground mb-2 line-clamp-2 text-sm font-semibold">{meme.name}</h3>
<div className="mb-3 flex flex-wrap gap-1">
{meme.keywords?.slice(0, 6).map((keyword, index) => <KeywordBadge key={index} keyword={keyword} />)}
{meme.keywords && meme.keywords.length > 6 && (
<Badge variant="secondary" className="text-xs">
+{meme.keywords.length - 6} more
</Badge>
)}
</div>
<div className="mt-auto">
<Link href={route('memes.show', meme.slug)}>
<Button
size="sm"
className="w-full bg-gradient-to-r from-purple-600 to-pink-600 text-white hover:from-purple-700 hover:to-pink-700"
>
Use meme
</Button>
</Link>
</div>
</div>
</Card>
))}
</div>
{/* Pagination */}
{memes.last_page > 1 && (
<div className="flex items-center justify-center gap-2">
{memes.links.map((link, index) => (
<Button
key={index}
variant={link.active ? 'default' : 'outline'}
size="sm"
onClick={() => link.url && handlePageChange(link.url)}
disabled={!link.url}
dangerouslySetInnerHTML={{ __html: link.label }}
/>
))}
</div>
)}
</div>
<Footer />
</div>
</>
);
}

View File

@@ -0,0 +1,174 @@
import { Head } from '@inertiajs/react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { ArrowLeft, Play, Download, Share2 } from 'lucide-react';
import { Link } from '@inertiajs/react';
import { route } from 'ziggy-js';
interface MemeMedia {
ids: string;
name: string;
description: string;
keywords: string[];
action_keywords: string[];
emotion_keywords: string[];
misc_keywords: string[];
mov_url: string;
webm_url: string;
gif_url: string;
webp_url: string;
slug: string;
}
interface Props {
meme: MemeMedia;
relatedMemes: MemeMedia[];
}
export default function MemeShow({ meme, relatedMemes }: Props) {
const allKeywords = [
...(meme.keywords || []),
...(meme.action_keywords || []),
...(meme.emotion_keywords || []),
...(meme.misc_keywords || [])
].filter(Boolean);
return (
<>
<Head title={`${meme.name} - Meme Template`} />
<Head>
<meta name="description" content={meme.description} />
<meta name="keywords" content={allKeywords.join(', ')} />
<meta property="og:title" content={`${meme.name} - Meme Template`} />
<meta property="og:description" content={meme.description} />
<meta property="og:image" content={meme.webp_url} />
<meta property="og:type" content="video.other" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={`${meme.name} - Meme Template`} />
<meta name="twitter:description" content={meme.description} />
<meta name="twitter:image" content={meme.webp_url} />
</Head>
<div className="min-h-screen bg-gradient-to-br from-purple-50 to-pink-50">
<div className="container mx-auto px-4 py-8">
{/* Header */}
<div className="flex items-center gap-4 mb-8">
<Link href={route('memes.index')}>
<Button variant="outline" size="sm">
<ArrowLeft className="h-4 w-4 mr-2" />
Back to Memes
</Button>
</Link>
<div>
<h1 className="text-3xl font-bold text-gray-900">{meme.name}</h1>
<p className="text-gray-600 mt-2">{meme.description}</p>
</div>
</div>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-8">
{/* Main Content */}
<div className="lg:col-span-2">
<Card>
<CardContent className="p-6">
{/* Video Preview */}
<div className="aspect-[9/16] bg-black rounded-lg overflow-hidden mb-6 max-w-md mx-auto">
<video
src={meme.webm_url}
poster={meme.webp_url}
controls
className="w-full h-full object-cover"
preload="metadata"
/>
</div>
{/* Action Buttons */}
<div className="flex flex-wrap gap-3 justify-center">
<Button className="bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-700 hover:to-pink-700">
<Play className="h-4 w-4 mr-2" />
Create Meme
</Button>
<Button variant="outline">
<Download className="h-4 w-4 mr-2" />
Download
</Button>
<Button variant="outline">
<Share2 className="h-4 w-4 mr-2" />
Share
</Button>
</div>
</CardContent>
</Card>
</div>
{/* Sidebar */}
<div className="space-y-6">
{/* Keywords */}
<Card>
<CardHeader>
<CardTitle className="text-lg">Keywords</CardTitle>
<CardDescription>
Related keywords for this meme template
</CardDescription>
</CardHeader>
<CardContent>
<div className="flex flex-wrap gap-2">
{meme.action_keywords?.map((keyword, index) => (
<Badge key={`action-${index}`} variant="secondary" className="bg-blue-100 text-blue-800">
{keyword}
</Badge>
))}
{meme.emotion_keywords?.map((keyword, index) => (
<Badge key={`emotion-${index}`} variant="secondary" className="bg-green-100 text-green-800">
{keyword}
</Badge>
))}
{meme.misc_keywords?.map((keyword, index) => (
<Badge key={`misc-${index}`} variant="secondary" className="bg-gray-100 text-gray-800">
{keyword}
</Badge>
))}
</div>
</CardContent>
</Card>
{/* Related Memes */}
{relatedMemes.length > 0 && (
<Card>
<CardHeader>
<CardTitle className="text-lg">Related Memes</CardTitle>
<CardDescription>
Similar meme templates you might like
</CardDescription>
</CardHeader>
<CardContent>
<div className="grid grid-cols-2 gap-3">
{relatedMemes.map((related) => (
<Link
key={related.ids}
href={route('memes.show', related.slug)}
className="block"
>
<div className="aspect-[9/16] bg-gray-100 rounded-lg overflow-hidden mb-2">
<img
src={related.webp_url}
alt={related.name}
className="w-full h-full object-cover hover:scale-105 transition-transform"
/>
</div>
<p className="text-sm font-medium text-gray-900 truncate">
{related.name}
</p>
</Link>
))}
</div>
</CardContent>
</Card>
)}
</div>
</div>
</div>
</div>
</>
);
}

File diff suppressed because one or more lines are too long

View File

@@ -4,6 +4,7 @@
use App\Http\Controllers\AdminDashboardController; use App\Http\Controllers\AdminDashboardController;
use App\Http\Controllers\AdminDuplicateController; use App\Http\Controllers\AdminDuplicateController;
use App\Http\Controllers\FrontHomeController; use App\Http\Controllers\FrontHomeController;
use App\Http\Controllers\FrontMemeController;
use App\Http\Controllers\FrontPagesController; use App\Http\Controllers\FrontPagesController;
use App\Http\Controllers\SocialAuthController; use App\Http\Controllers\SocialAuthController;
use App\Http\Controllers\UserDashboardController; use App\Http\Controllers\UserDashboardController;
@@ -75,6 +76,18 @@
->middleware('cacheResponse') ->middleware('cacheResponse')
->name('terms'); ->name('terms');
Route::get('/meme-library', [FrontMemeController::class, 'index'])
->middleware('cacheResponse')
->name('memes.index');
Route::get('/meme-library/{search}', [FrontMemeController::class, 'search'])
->middleware('cacheResponse')
->name('memes.search');
Route::get('/meme/{slug}', [FrontMemeController::class, 'show'])
->middleware('cacheResponse')
->name('memes.show');
// Admin Tools with Basic Auth // Admin Tools with Basic Auth
Route::prefix('duplicates')->middleware([BasicAuthMiddleware::class])->group(function () { Route::prefix('duplicates')->middleware([BasicAuthMiddleware::class])->group(function () {
Route::get('/', [AdminDuplicateController::class, 'index'])->name('admin.duplicates'); Route::get('/', [AdminDuplicateController::class, 'index'])->name('admin.duplicates');