Spaces:
Runtime error
Runtime error
Commit ·
de12c7f
1
Parent(s): c93270a
feat: enhance note preview layout and add YouTube link embedding functionality
Browse files- app/templates/note_preview.html +132 -76
app/templates/note_preview.html
CHANGED
|
@@ -2,87 +2,143 @@
|
|
| 2 |
|
| 3 |
{% block content %}
|
| 4 |
<div class="max-w-7xl mx-auto px-4 sm:px-6">
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
Back to Notes
|
| 11 |
-
</a>
|
| 12 |
-
|
| 13 |
-
<h1 class="font-display text-5xl font-bold tracking-tight mb-4">
|
| 14 |
-
{{ note.title }}
|
| 15 |
</h1>
|
| 16 |
-
|
| 17 |
-
<div class="flex flex-wrap gap-3 mb-6
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
</div>
|
| 32 |
-
|
| 33 |
{% if note.description %}
|
| 34 |
-
<p class="font-mono text-gray-300
|
| 35 |
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
</div>
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
{% if ext in ['jpg', 'jpeg', 'png', 'gif', 'webp'] %}
|
| 54 |
-
<img src="{{ note.presigned_url }}" class="w-full rounded-xl" alt="{{ note.title }}">
|
| 55 |
-
{% elif ext == 'pdf' %}
|
| 56 |
-
<iframe src="{{ note.presigned_url }}" class="w-full h-[600px] rounded-xl bg-white/5"></iframe>
|
| 57 |
-
{% elif ext in ['mp4', 'webm', 'ogg'] %}
|
| 58 |
-
<video controls class="w-full rounded-xl">
|
| 59 |
-
<source src="{{ note.presigned_url }}" type="video/{{ ext }}">
|
| 60 |
-
</video>
|
| 61 |
-
{% elif ext in ['mp3', 'wav', 'ogg'] %}
|
| 62 |
-
<audio controls class="w-full">
|
| 63 |
-
<source src="{{ note.presigned_url }}" type="audio/{{ ext }}">
|
| 64 |
-
</audio>
|
| 65 |
-
{% elif ext in ['txt', 'md'] %}
|
| 66 |
-
<iframe src="{{ note.presigned_url }}" class="w-full h-[600px] rounded-xl bg-white/5"></iframe>
|
| 67 |
-
{% else %}
|
| 68 |
-
<div class="text-center py-12">
|
| 69 |
-
<p class="font-mono text-gray-400 mb-4">Preview not available for this file type</p>
|
| 70 |
-
<p class="font-mono text-sm text-gray-500">{{ note.link.split('/')[-1] }}</p>
|
| 71 |
-
</div>
|
| 72 |
-
{% endif %}
|
| 73 |
-
{% endif %}
|
| 74 |
</div>
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
</div>
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
{% block content %}
|
| 4 |
<div class="max-w-7xl mx-auto px-4 sm:px-6">
|
| 5 |
+
<div class="mb-8">
|
| 6 |
+
<div class="flex flex-col-reverse sm:flex-row sm:items-start sm:justify-between gap-4 mb-4">
|
| 7 |
+
<div>
|
| 8 |
+
<h1 class="font-display text-4xl sm:text-5xl font-bold tracking-tight mb-4">
|
| 9 |
+
{{ note.title }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
</h1>
|
| 11 |
+
|
| 12 |
+
<div class="flex flex-wrap gap-3 mb-6">
|
| 13 |
+
<span class="px-4 py-2 bg-blue-500/20 border border-blue-500/50 rounded-lg font-mono text-sm">
|
| 14 |
+
{{ note.subject.name }}
|
| 15 |
+
</span>
|
| 16 |
+
<span class="px-4 py-2 bg-purple-500/20 border border-purple-500/50 rounded-lg font-mono text-sm">
|
| 17 |
+
{{ note.note_type.name }}
|
| 18 |
+
</span>
|
| 19 |
+
<span class="glass rounded-lg font-mono text-sm text-gray-400 flex items-center gap-2 px-3 py-2">
|
| 20 |
+
<img src="https://api.dicebear.com/9.x/thumbs/svg?seed={{ note.user.email }}"
|
| 21 |
+
alt="{{ note.user.name }} Avatar" class="w-6 h-6 rounded-full">
|
| 22 |
+
by {{ note.user.name }}
|
| 23 |
+
</span>
|
| 24 |
+
<span class="px-4 py-2 glass rounded-lg font-mono text-sm text-gray-400">
|
| 25 |
+
{{ note.created_at.strftime('%b %d, %Y') }}
|
| 26 |
+
</span>
|
| 27 |
</div>
|
| 28 |
+
|
| 29 |
{% if note.description %}
|
| 30 |
+
<p class="font-mono text-gray-300 max-w-3xl">{{ note.description }}</p>
|
| 31 |
{% endif %}
|
| 32 |
+
</div>
|
| 33 |
+
|
| 34 |
+
<a href="{{ url_for('notes.list') }}"
|
| 35 |
+
class="inline-flex items-center gap-2 font-mono text-sm text-gray-400 hover:text-blue-400 transition whitespace-nowrap">
|
| 36 |
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 37 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
|
| 38 |
+
</svg>
|
| 39 |
+
Back to Notes
|
| 40 |
+
</a>
|
| 41 |
</div>
|
| 42 |
+
</div>
|
| 43 |
+
|
| 44 |
+
<!-- Preview Area -->
|
| 45 |
+
<div class="glass p-4 sm:p-8 rounded-2xl mb-8" id="preview-container">
|
| 46 |
+
{% if note.original_link %}
|
| 47 |
+
<div id="link-preview" class="text-center py-8" data-url="{{ note.presigned_url }}">
|
| 48 |
+
<p class="font-mono text-sm text-gray-400 mb-4">External Link</p>
|
| 49 |
+
<a href="{{ note.presigned_url }}" target="_blank"
|
| 50 |
+
class="inline-flex items-center gap-2 font-mono text-blue-400 hover:text-blue-300 transition break-all">
|
| 51 |
+
{{ note.presigned_url }}
|
| 52 |
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 53 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
| 54 |
+
d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
|
| 55 |
+
</svg>
|
| 56 |
+
</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
</div>
|
| 58 |
+
{% else %}
|
| 59 |
+
{% set ext = note.link.split('.')[-1].lower() %}
|
| 60 |
+
|
| 61 |
+
{% if ext in ['jpg', 'jpeg', 'png', 'gif', 'webp'] %}
|
| 62 |
+
<img src="{{ note.presigned_url }}" class="w-full rounded-xl" alt="{{ note.title }}">
|
| 63 |
+
{% elif ext == 'pdf' %}
|
| 64 |
+
<iframe src="{{ note.presigned_url }}" class="w-full h-[600px] rounded-xl bg-white/5"></iframe>
|
| 65 |
+
{% elif ext in ['mp4', 'webm', 'ogg'] %}
|
| 66 |
+
<video controls class="w-full rounded-xl">
|
| 67 |
+
<source src="{{ note.presigned_url }}" type="video/{{ ext }}">
|
| 68 |
+
</video>
|
| 69 |
+
{% elif ext in ['mp3', 'wav', 'ogg'] %}
|
| 70 |
+
<audio controls class="w-full">
|
| 71 |
+
<source src="{{ note.presigned_url }}" type="audio/{{ ext }}">
|
| 72 |
+
</audio>
|
| 73 |
+
{% elif ext in ['txt', 'md'] %}
|
| 74 |
+
<iframe src="{{ note.presigned_url }}" class="w-full h-[600px] rounded-xl bg-white/5"></iframe>
|
| 75 |
+
{% else %}
|
| 76 |
+
<div class="text-center py-12">
|
| 77 |
+
<p class="font-mono text-gray-400 mb-4">Preview not available for this file type</p>
|
| 78 |
+
<p class="font-mono text-sm text-gray-500">{{ note.link.split('/')[-1] }}</p>
|
| 79 |
</div>
|
| 80 |
+
{% endif %}
|
| 81 |
+
{% endif %}
|
| 82 |
+
</div>
|
| 83 |
+
|
| 84 |
+
<!-- Actions -->
|
| 85 |
+
<div class="flex gap-4">
|
| 86 |
+
{% if note.presigned_url %}
|
| 87 |
+
{% if note.original_link %}
|
| 88 |
+
<a href="{{ note.presigned_url }}" target="_blank"
|
| 89 |
+
class="btn-magnetic glass px-8 py-4 rounded-xl font-mono font-semibold border-2 border-blue-500/50 hover:border-blue-400 animate-glow text-center">
|
| 90 |
+
Go To Site
|
| 91 |
+
</a>
|
| 92 |
+
{% else %}
|
| 93 |
+
<a href="{{ note.presigned_url }}" download
|
| 94 |
+
class="btn-magnetic glass px-8 py-4 rounded-xl font-mono font-semibold border-2 border-blue-500/50 hover:border-blue-400 animate-glow text-center">
|
| 95 |
+
Download
|
| 96 |
+
</a>
|
| 97 |
+
{% endif %}
|
| 98 |
+
{% endif %}
|
| 99 |
+
<a href="{{ url_for('notes.share', id=note.id) }}"
|
| 100 |
+
class="btn-magnetic glass px-8 py-4 rounded-xl font-mono font-semibold hover:bg-white/5 text-center">
|
| 101 |
+
Share
|
| 102 |
+
</a>
|
| 103 |
+
</div>
|
| 104 |
</div>
|
| 105 |
+
|
| 106 |
+
<script>
|
| 107 |
+
document.addEventListener('DOMContentLoaded', function () {
|
| 108 |
+
const linkPreview = document.getElementById('link-preview');
|
| 109 |
+
if (linkPreview) {
|
| 110 |
+
const url = linkPreview.getAttribute('data-url');
|
| 111 |
+
|
| 112 |
+
// Regex for Playlist
|
| 113 |
+
const playlistRegex = /[?&]list=([^#\&\?]+)/;
|
| 114 |
+
const playlistMatch = url.match(playlistRegex);
|
| 115 |
+
|
| 116 |
+
// Regex for Video
|
| 117 |
+
const videoRegex = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/i;
|
| 118 |
+
const videoMatch = url.match(videoRegex);
|
| 119 |
+
|
| 120 |
+
let embedUrl = null;
|
| 121 |
+
|
| 122 |
+
if (playlistMatch && playlistMatch[1]) {
|
| 123 |
+
embedUrl = `https://www.youtube.com/embed/videoseries?list=${playlistMatch[1]}`;
|
| 124 |
+
} else if (videoMatch && videoMatch[1]) {
|
| 125 |
+
embedUrl = `https://www.youtube.com/embed/${videoMatch[1]}`;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
if (embedUrl) {
|
| 129 |
+
const iframe = document.createElement('iframe');
|
| 130 |
+
iframe.setAttribute('src', embedUrl);
|
| 131 |
+
iframe.setAttribute('class', 'w-full aspect-video rounded-xl shadow-lg');
|
| 132 |
+
iframe.setAttribute('frameborder', '0');
|
| 133 |
+
iframe.setAttribute('allow', 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture');
|
| 134 |
+
iframe.setAttribute('allowfullscreen', 'true');
|
| 135 |
+
iframe.setAttribute('loading', 'eager');
|
| 136 |
+
|
| 137 |
+
linkPreview.innerHTML = '';
|
| 138 |
+
linkPreview.appendChild(iframe);
|
| 139 |
+
linkPreview.classList.remove('text-center', 'py-8');
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
});
|
| 143 |
+
</script>
|
| 144 |
+
{% endblock %}
|