common datetime display
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
---
|
||||
import Layout from '../layouts/Layout.astro';
|
||||
import { formatDateTime } from '../utils/dateFormat';
|
||||
|
||||
const WIKIJS_BASE_URL = 'https://wiki.teletype.hu';
|
||||
const WIKIJS_TOKEN = import.meta.env.WEBAPP_WIKIJS_TOKEN;
|
||||
@@ -107,20 +108,6 @@ try {
|
||||
error = `Failed to fetch wiki data: ${e.message}`;
|
||||
}
|
||||
|
||||
function timeAgo(dateStr: string): string {
|
||||
const now = new Date();
|
||||
const date = new Date(dateStr);
|
||||
const diffMs = now.getTime() - date.getTime();
|
||||
const diffMins = Math.floor(diffMs / 60000);
|
||||
const diffHours = Math.floor(diffMins / 60);
|
||||
const diffDays = Math.floor(diffHours / 24);
|
||||
|
||||
if (diffMins < 1) return 'just now';
|
||||
if (diffMins < 60) return `${diffMins}m ago`;
|
||||
if (diffHours < 24) return `${diffHours}h ago`;
|
||||
if (diffDays < 30) return `${diffDays}d ago`;
|
||||
return date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
|
||||
}
|
||||
|
||||
function getPermalink(path: string): string {
|
||||
const slug = path.startsWith('blog/') ? path.replace('blog/', '') : path;
|
||||
@@ -195,7 +182,7 @@ function getCleanPreview(content: string): string {
|
||||
New Post
|
||||
</span>
|
||||
)}
|
||||
<span>{timeAgo(page.createdAt)}</span>
|
||||
<span>{formatDateTime(page.createdAt)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
import { formatDateTime } from '../../utils/dateFormat';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const WIKIJS_BASE_URL = 'https://wiki.teletype.hu';
|
||||
@@ -110,20 +111,6 @@ try {
|
||||
error = e.message;
|
||||
}
|
||||
|
||||
function timeAgo(dateStr: string): string {
|
||||
const now = new Date();
|
||||
const date = new Date(dateStr);
|
||||
const diffMs = now.getTime() - date.getTime();
|
||||
const diffMins = Math.floor(diffMs / 60000);
|
||||
const diffHours = Math.floor(diffMins / 60);
|
||||
const diffDays = Math.floor(diffHours / 24);
|
||||
|
||||
if (diffMins < 1) return 'just now';
|
||||
if (diffMins < 60) return `${diffMins}m ago`;
|
||||
if (diffHours < 24) return `${diffHours}h ago`;
|
||||
if (diffDays < 30) return `${diffDays}d ago`;
|
||||
return date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
|
||||
}
|
||||
---
|
||||
|
||||
<Layout>
|
||||
@@ -147,7 +134,7 @@ function timeAgo(dateStr: string): string {
|
||||
{pageContent.description}
|
||||
</p>
|
||||
<div class="blog-post-timestamp text-indigo-200">
|
||||
{timeAgo(pageContent.createdAt)}
|
||||
{formatDateTime(pageContent.createdAt)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
import Layout from '../layouts/Layout.astro';
|
||||
import { formatDateTime } from '../utils/dateFormat';
|
||||
const BASE = "https://games.teletype.hu";
|
||||
const API = BASE + "/api/software";
|
||||
|
||||
@@ -90,8 +91,8 @@ const softwares = json.softwares;
|
||||
{stableReleases.map((release: any) => (
|
||||
<tr>
|
||||
<td class="releases-td font-medium text-gray-900">{release.version}</td>
|
||||
<td class="releases-td text-gray-500">{new Date(release.CreatedAt).toLocaleDateString('en-US')}</td>
|
||||
<td class="releases-td text-gray-500">{new Date(release.UpdatedAt).toLocaleDateString('en-US')}</td>
|
||||
<td class="releases-td text-gray-500">{formatDateTime(release.CreatedAt)}</td>
|
||||
<td class="releases-td text-gray-500">{formatDateTime(release.UpdatedAt)}</td>
|
||||
<td class="releases-td text-right">
|
||||
{release.htmlFolderPath ? (<a href={BASE + release.htmlFolderPath} target="_blank" class="action-link-purple">▶ Play</a>) : (<span class="action-link-disabled">▶ Play</span>)}
|
||||
{release.cartridgePath ? (<a href={BASE + release.cartridgePath} target="_blank" class="action-link-blue">Download</a>) : (<span class="action-link-disabled">Download</span>)}
|
||||
@@ -108,8 +109,8 @@ const softwares = json.softwares;
|
||||
{devReleases.map((release: any) => (
|
||||
<tr class="bg-yellow-50/50">
|
||||
<td class="releases-td font-medium text-yellow-800">{release.version}</td>
|
||||
<td class="releases-td text-gray-500">{new Date(release.CreatedAt).toLocaleDateString('en-US')}</td>
|
||||
<td class="releases-td text-gray-500">{new Date(release.UpdatedAt).toLocaleDateString('en-US')}</td>
|
||||
<td class="releases-td text-gray-500">{formatDateTime(release.CreatedAt)}</td>
|
||||
<td class="releases-td text-gray-500">{formatDateTime(release.UpdatedAt)}</td>
|
||||
<td class="releases-td text-right">
|
||||
{release.htmlFolderPath ? (<a href={BASE + release.htmlFolderPath} target="_blank" class="action-link-purple">▶ Play</a>) : (<span class="action-link-disabled">▶ Play</span>)}
|
||||
{release.cartridgePath ? (<a href={BASE + release.cartridgePath} target="_blank" class="action-link-blue">Download</a>) : (<span class="action-link-disabled">Download</span>)}
|
||||
@@ -128,8 +129,8 @@ const softwares = json.softwares;
|
||||
<div class="release-mobile-card">
|
||||
<div class="release-mobile-header">
|
||||
<span class="release-mobile-version">{release.version}</span>
|
||||
<span class="release-mobile-date">Created: {new Date(release.CreatedAt).toLocaleDateString('en-US')}</span>
|
||||
<span class="release-mobile-date">Updated: {new Date(release.UpdatedAt).toLocaleDateString('en-US')}</span>
|
||||
<span class="release-mobile-date">Created: {formatDateTime(release.CreatedAt)}</span>
|
||||
<span class="release-mobile-date">Updated: {formatDateTime(release.UpdatedAt)}</span>
|
||||
</div>
|
||||
<div class="release-mobile-grid">
|
||||
{release.htmlFolderPath ? (<a href={BASE + release.htmlFolderPath} target="_blank" class="mobile-btn-play">▶ Play</a>) : (<span class="mobile-btn-disabled">▶ Play</span>)}
|
||||
@@ -146,8 +147,8 @@ const softwares = json.softwares;
|
||||
<div class="release-mobile-card border-yellow-200 bg-yellow-50">
|
||||
<div class="release-mobile-header">
|
||||
<span class="release-mobile-version text-yellow-800">{release.version}</span>
|
||||
<span class="release-mobile-date">Created: {new Date(release.CreatedAt).toLocaleDateString('en-US')}</span>
|
||||
<span class="release-mobile-date">Updated: {new Date(release.UpdatedAt).toLocaleDateString('en-US')}</span>
|
||||
<span class="release-mobile-date">Created: {formatDateTime(release.CreatedAt)}</span>
|
||||
<span class="release-mobile-date">Updated: {formatDateTime(release.UpdatedAt)}</span>
|
||||
</div>
|
||||
<div class="release-mobile-grid">
|
||||
{release.htmlFolderPath ? (<a href={BASE + release.htmlFolderPath} target="_blank" class="mobile-btn-play">▶ Play</a>) : (<span class="mobile-btn-disabled">▶ Play</span>)}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
import Layout from '../layouts/Layout.astro';
|
||||
import { formatDateTime } from '../utils/dateFormat';
|
||||
|
||||
const GITEA_API_BASE_URL = 'https://git.teletype.hu/api/v1';
|
||||
const GITEA_TOKEN = import.meta.env.WEBAPP_GITEA_TOKEN;
|
||||
@@ -152,7 +153,7 @@ const recentCommits = allCommits.slice(0, 20);
|
||||
</h3>
|
||||
{repo.description && <p class="repo-card-desc">{repo.description}</p>}
|
||||
{repo.language && <p class="repo-card-meta">Language: {repo.language}</p>}
|
||||
<p class="repo-card-meta">Updated: {new Date(repo.updated_at).toLocaleDateString('en-US', {year: 'numeric', month: 'short', day: 'numeric'})}</p>
|
||||
<p class="repo-card-meta">Updated: {formatDateTime(repo.updated_at)}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -178,9 +179,7 @@ const recentCommits = allCommits.slice(0, 20);
|
||||
: <span class="text-gray-700">{commit.message.split('\n')[0]}</span>
|
||||
</p>
|
||||
<p class="commit-meta">
|
||||
Authored by <span class="font-bold">{commit.author.name}</span> on {new Date(commit.date).toLocaleDateString('en-US', {
|
||||
year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit'
|
||||
})}
|
||||
Authored by <span class="font-bold">{commit.author.name}</span> on {formatDateTime(commit.date)}
|
||||
<a href={commit.url} target="_blank" class="commit-sha-link">
|
||||
<span class="font-mono text-xs">{commit.sha.substring(0, 7)}</span>
|
||||
</a>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
import Layout from '../layouts/Layout.astro';
|
||||
import { formatDateTime } from '../utils/dateFormat';
|
||||
|
||||
const WIKIJS_BASE_URL = 'https://wiki.teletype.hu';
|
||||
const WIKIJS_TOKEN = import.meta.env.WEBAPP_WIKIJS_TOKEN;
|
||||
@@ -77,20 +78,6 @@ try {
|
||||
error = `Failed to fetch wiki data: ${e.message}`;
|
||||
}
|
||||
|
||||
function timeAgo(dateStr: string): string {
|
||||
const now = new Date();
|
||||
const date = new Date(dateStr);
|
||||
const diffMs = now.getTime() - date.getTime();
|
||||
const diffMins = Math.floor(diffMs / 60000);
|
||||
const diffHours = Math.floor(diffMins / 60);
|
||||
const diffDays = Math.floor(diffHours / 24);
|
||||
|
||||
if (diffMins < 1) return 'just now';
|
||||
if (diffMins < 60) return `${diffMins}m ago`;
|
||||
if (diffHours < 24) return `${diffHours}h ago`;
|
||||
if (diffDays < 30) return `${diffDays}d ago`;
|
||||
return date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
|
||||
}
|
||||
---
|
||||
|
||||
<Layout>
|
||||
@@ -162,7 +149,7 @@ function timeAgo(dateStr: string): string {
|
||||
New
|
||||
</span>
|
||||
)}
|
||||
<span>{timeAgo(page.updatedAt)}</span>
|
||||
<span>{formatDateTime(page.updatedAt)}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
import Layout from '../layouts/Layout.astro';
|
||||
import { formatDateTime } from '../utils/dateFormat';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import yaml from 'js-yaml';
|
||||
@@ -43,19 +44,13 @@ try {
|
||||
name: first.name,
|
||||
date: first.date,
|
||||
dateISO: first.dateObj.toISOString(),
|
||||
dateText: first.dateObj.toLocaleString('en-US', {
|
||||
year: 'numeric', month: 'short', day: 'numeric',
|
||||
hour: '2-digit', minute: '2-digit'
|
||||
})
|
||||
dateText: formatDateTime(first.dateObj)
|
||||
};
|
||||
|
||||
followingEvents = futureEvents.slice(1).map(e => ({
|
||||
name: e.name,
|
||||
date: e.date,
|
||||
dateText: e.dateObj.toLocaleString('en-US', {
|
||||
year: 'numeric', month: 'short', day: 'numeric',
|
||||
hour: '2-digit', minute: '2-digit'
|
||||
})
|
||||
dateText: formatDateTime(e.dateObj)
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -567,7 +562,12 @@ const YOUTUBE_CHANNEL_ID = import.meta.env.YOUTUBE_CHANNEL_ID;
|
||||
|
||||
function formatDate(iso) {
|
||||
const d = new Date(iso);
|
||||
return d.toLocaleDateString('en-US', { year:'numeric', month:'long', day:'numeric' });
|
||||
const y = d.getFullYear();
|
||||
const m = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
const h = String(d.getHours()).padStart(2, '0');
|
||||
const min = String(d.getMinutes()).padStart(2, '0');
|
||||
return `${y}-${m}-${day} ${h}:${min}`;
|
||||
}
|
||||
|
||||
function formatViews(n) {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Központi dátum formátum konfiguráció
|
||||
// A formátum megváltoztatásához csak itt kell módosítani.
|
||||
export const DATETIME_FORMAT = 'YYYY-MM-DD HH:mm';
|
||||
export const DATE_FORMAT = 'YYYY-MM-DD';
|
||||
|
||||
export function formatDateTime(dateStr: string | Date): string {
|
||||
const d = new Date(dateStr as string);
|
||||
const year = d.getFullYear();
|
||||
const month = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
const hours = String(d.getHours()).padStart(2, '0');
|
||||
const minutes = String(d.getMinutes()).padStart(2, '0');
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
||||
}
|
||||
|
||||
export function formatDate(dateStr: string | Date): string {
|
||||
const d = new Date(dateStr as string);
|
||||
const year = d.getFullYear();
|
||||
const month = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
Reference in New Issue
Block a user