lexipedia / index.html
Evosh's picture
Create a Dictionary, with a dictionary section, and a history section.
a43ac2a verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LexiPedia - Dictionary & History</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#6366f1',
secondary: '#8b5cf6',
dark: '#1e293b',
light: '#f8fafc'
}
}
}
}
</script>
<style>
body {
font-family: 'Inter', sans-serif;
background: linear-gradient(135deg, #f0f4ff 0%, #e6e9ff 100%);
}
.word-card {
transition: all 0.3s ease;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}
.word-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
}
.history-item {
border-left: 3px solid #8b5cf6;
}
.search-btn {
transition: all 0.3s ease;
}
.search-btn:hover {
transform: scale(1.05);
}
.fade-in {
animation: fadeIn 0.5s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body class="min-h-screen">
<!-- Header -->
<header class="bg-white shadow-sm">
<div class="container mx-auto px-4 py-4 flex justify-between items-center">
<div class="flex items-center space-x-2">
<i data-feather="book-open" class="text-primary w-8 h-8"></i>
<h1 class="text-2xl font-bold text-dark">LexiPedia</h1>
</div>
<nav>
<ul class="flex space-x-6">
<li><a href="#" class="text-primary font-medium flex items-center"><i data-feather="search" class="mr-1 w-4 h-4"></i> Dictionary</a></li>
<li><a href="#" class="text-gray-600 hover:text-primary flex items-center"><i data-feather="clock" class="mr-1 w-4 h-4"></i> History</a></li>
</ul>
</nav>
</div>
</header>
<main class="container mx-auto px-4 py-8">
<!-- Dictionary Section -->
<section class="mb-16">
<div class="text-center mb-10">
<h2 class="text-3xl font-bold text-dark mb-2">Dictionary</h2>
<p class="text-gray-600 max-w-2xl mx-auto">Search for definitions, synonyms, and examples of any word in the English language</p>
</div>
<!-- Search Bar -->
<div class="max-w-2xl mx-auto mb-12">
<div class="relative">
<input
type="text"
id="searchInput"
placeholder="Search for a word..."
class="w-full px-6 py-4 rounded-full border border-gray-300 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent shadow-sm text-lg"
>
<button
id="searchBtn"
class="absolute right-2 top-2 bg-primary text-white rounded-full px-6 py-2 search-btn flex items-center"
>
<i data-feather="search" class="mr-2"></i> Search
</button>
</div>
</div>
<!-- Word Display -->
<div id="wordDisplay" class="max-w-4xl mx-auto">
<!-- Word card will be inserted here by JS -->
</div>
</section>
<!-- History Section -->
<section>
<div class="flex items-center justify-between mb-6">
<h2 class="text-2xl font-bold text-dark">Search History</h2>
<button id="clearHistory" class="text-sm text-red-500 hover:text-red-700 flex items-center">
<i data-feather="trash-2" class="mr-1 w-4 h-4"></i> Clear History
</button>
</div>
<div id="historyList" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<!-- History items will be inserted here by JS -->
</div>
</section>
</main>
<footer class="bg-white border-t mt-12 py-6">
<div class="container mx-auto px-4 text-center text-gray-600">
<p>© 2023 LexiPedia. All rights reserved.</p>
</div>
</footer>
<script>
// Initialize Feather Icons
feather.replace();
// Sample word data (in a real app, this would come from an API)
const wordData = {
"example": {
word: "example",
phonetic: "/ɪɡˈzæmpəl/",
meanings: [
{
partOfSpeech: "noun",
definitions: [
{
definition: "A representative form or pattern",
example: "This is a good example of modern architecture."
},
{
definition: "A task performed or problem solved that shows the way to do or solve others",
example: "Follow my example and you'll succeed."
}
]
},
{
partOfSpeech: "verb",
definitions: [
{
definition: "To be illustrated or exemplified",
example: "The report exemplifies the problems facing the industry."
}
]
}
],
synonyms: ["sample", "instance", "case", "illustration"],
antonyms: ["counterexample"]
}
};
// DOM Elements
const searchInput = document.getElementById('searchInput');
const searchBtn = document.getElementById('searchBtn');
const wordDisplay = document.getElementById('wordDisplay');
const historyList = document.getElementById('historyList');
const clearHistoryBtn = document.getElementById('clearHistory');
// History array
let searchHistory = JSON.parse(localStorage.getItem('lexipediaHistory')) || [];
// Display word function
function displayWord(word) {
const data = wordData[word.toLowerCase()] || null;
if (!data) {
wordDisplay.innerHTML = `
<div class="bg-white rounded-xl shadow-md p-8 text-center">
<i data-feather="alert-circle" class="w-16 h-16 text-gray-400 mx-auto mb-4"></i>
<h3 class="text-xl font-semibold text-gray-700 mb-2">Word not found</h3>
<p class="text-gray-600">Sorry, we couldn't find the word "${word}" in our dictionary.</p>
</div>
`;
feather.replace();
return;
}
let meaningsHTML = '';
data.meanings.forEach(meaning => {
let definitionsHTML = '';
meaning.definitions.forEach(def => {
definitionsHTML += `
<div class="mb-4">
<p class="text-gray-700 mb-2">${def.definition}</p>
${def.example ? `<p class="text-gray-500 italic">"${def.example}"</p>` : ''}
</div>
`;
});
meaningsHTML += `
<div class="mb-6">
<h4 class="text-lg font-semibold text-primary mb-3">${meaning.partOfSpeech}</h4>
${definitionsHTML}
</div>
`;
});
let synonymsHTML = '';
if (data.synonyms && data.synonyms.length > 0) {
synonymsHTML = `
<div class="mb-6">
<h4 class="text-lg font-semibold text-primary mb-3">Synonyms</h4>
<div class="flex flex-wrap gap-2">
${data.synonyms.map(syn => `<span class="bg-purple-100 text-purple-800 px-3 py-1 rounded-full text-sm">${syn}</span>`).join('')}
</div>
</div>
`;
}
wordDisplay.innerHTML = `
<div class="word-card bg-white rounded-xl shadow-md overflow-hidden fade-in">
<div class="p-6">
<div class="flex justify-between items-start mb-4">
<div>
<h3 class="text-3xl font-bold text-dark">${data.word}</h3>
<p class="text-gray-600">${data.phonetic}</p>
</div>
<button class="text-gray-400 hover:text-primary">
<i data-feather="volume-2" class="w-6 h-6"></i>
</button>
</div>
${meaningsHTML}
${synonymsHTML}
</div>
</div>
`;
feather.replace();
// Add to history
addToHistory(data.word);
}
// Add to history function
function addToHistory(word) {
// Remove if already exists
searchHistory = searchHistory.filter(item => item !== word);
// Add to beginning
searchHistory.unshift(word);
// Keep only last 10 items
if (searchHistory.length > 10) {
searchHistory = searchHistory.slice(0, 10);
}
// Save to localStorage
localStorage.setItem('lexipediaHistory', JSON.stringify(searchHistory));
// Update history display
displayHistory();
}
// Display history function
function displayHistory() {
if (searchHistory.length === 0) {
historyList.innerHTML = `
<div class="col-span-full text-center py-8">
<i data-feather="clock" class="w-12 h-12 text-gray-400 mx-auto mb-4"></i>
<p class="text-gray-600">Your search history is empty</p>
</div>
`;
feather.replace();
return;
}
historyList.innerHTML = searchHistory.map(word => `
<div class="history-item bg-white rounded-lg shadow-sm p-4 cursor-pointer hover:bg-gray-50 transition-colors">
<div class="flex items-center">
<i data-feather="search" class="w-5 h-5 text-secondary mr-3"></i>
<span class="font-medium text-dark">${word}</span>
</div>
</div>
`).join('');
feather.replace();
// Add click events to history items
document.querySelectorAll('#historyList .history-item').forEach((item, index) => {
item.addEventListener('click', () => {
searchInput.value = searchHistory[index];
displayWord(searchHistory[index]);
// Scroll to dictionary section
document.querySelector('section').scrollIntoView({ behavior: 'smooth' });
});
});
}
// Clear history function
function clearHistory() {
searchHistory = [];
localStorage.removeItem('lexipediaHistory');
displayHistory();
}
// Event Listeners
searchBtn.addEventListener('click', () => {
const word = searchInput.value.trim();
if (word) {
displayWord(word);
}
});
searchInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
const word = searchInput.value.trim();
if (word) {
displayWord(word);
}
}
});
clearHistoryBtn.addEventListener('click', clearHistory);
// Initialize
displayHistory();
// Show example word on load
window.addEventListener('load', () => {
searchInput.value = 'example';
displayWord('example');
});
</script>
</body>
</html>