Preserve historical publication days across build timezones
Build and deploy / deploy (push) Successful in 5m24s
Build and deploy / deploy (push) Successful in 5m24s
This commit is contained in:
1 parent
2d5a687fda
commit
0cb1ce1f15
6 files changed
+37
-5
No files matched your search
+2
-1
@@ -1,4 +1,5 @@
|
||||
"use client";
|
||||
import {useState,useEffect} from 'react';
|
||||
import Link from 'next/link';
|
||||
export default function Catalog({articles}){const [q,setQ]=useState(''),[topic,setTopic]=useState('Все');const topics=['Все',...new Set(articles.flatMap(a=>a.categories))];const shown=articles.filter(a=>(topic==='Все'||a.categories.includes(topic))&&(a.title+' '+a.excerpt+' '+a.categories.join(' ')).toLocaleLowerCase('ru').includes(q.toLocaleLowerCase('ru')));return <section id="journal" className="journal"><div className="journal-heading"><div><p className="kicker">ПОЛНЫЙ ИНДЕКС</p><h2>Статьи и заметки</h2></div><span>{articles.length} материалов</span></div><div className="catalog-controls"><label htmlFor="search"><span>Найти в журнале</span><input id="search" type="search" value={q} onChange={e=>setQ(e.target.value)} placeholder="Тема, язык или задача"/></label><div className="topic-tabs" aria-label="Темы">{topics.map(t=><button aria-pressed={topic===t} key={t} onClick={()=>setTopic(t)}>{t}</button>)}</div></div><p role="status" className="search-status">{shown.length?`Найдено материалов: ${shown.length}`:'По этому запросу ничего нет. Попробуйте другое слово или сбросьте тему.'}</p><div className="journal-list">{shown.map(a=><article key={a.slug} className="index-entry"><div className="index-date"><time dateTime={a.date}>{new Intl.DateTimeFormat('ru-RU',{year:'numeric',month:'short',day:'numeric',timeZone:'UTC'}).format(new Date(a.date))}</time><span>{a.categories.join(' · ')}</span></div><Link href={'/articles/'+encodeURIComponent(a.slug)+'/'}><h3>{a.title}</h3><p>{a.excerpt}</p></Link><span className="index-duration">{a.readingMinutes} мин <b aria-hidden="true">↗</b></span></article>)}</div>{!shown.length&&<button onClick={()=>{setQ('');setTopic('Все');}}>Сбросить поиск</button>}</section>}
|
||||
import {formatDate} from '../lib/dates.mjs';
|
||||
export default function Catalog({articles}){const [q,setQ]=useState(''),[topic,setTopic]=useState('Все');const topics=['Все',...new Set(articles.flatMap(a=>a.categories))];const shown=articles.filter(a=>(topic==='Все'||a.categories.includes(topic))&&(a.title+' '+a.excerpt+' '+a.categories.join(' ')).toLocaleLowerCase('ru').includes(q.toLocaleLowerCase('ru')));return <section id="journal" className="journal"><div className="journal-heading"><div><p className="kicker">ПОЛНЫЙ ИНДЕКС</p><h2>Статьи и заметки</h2></div><span>{articles.length} материалов</span></div><div className="catalog-controls"><label htmlFor="search"><span>Найти в журнале</span><input id="search" type="search" value={q} onChange={e=>setQ(e.target.value)} placeholder="Тема, язык или задача"/></label><div className="topic-tabs" aria-label="Темы">{topics.map(t=><button aria-pressed={topic===t} key={t} onClick={()=>setTopic(t)}>{t}</button>)}</div></div><p role="status" className="search-status">{shown.length?`Найдено материалов: ${shown.length}`:'По этому запросу ничего нет. Попробуйте другое слово или сбросьте тему.'}</p><div className="journal-list">{shown.map(a=><article key={a.slug} className="index-entry"><div className="index-date"><time dateTime={a.date}>{formatDate(a.date,{month:'short',day:'numeric'})}</time><span>{a.categories.join(' · ')}</span></div><Link href={'/articles/'+encodeURIComponent(a.slug)+'/'}><h3>{a.title}</h3><p>{a.excerpt}</p></Link><span className="index-duration">{a.readingMinutes} мин <b aria-hidden="true">↗</b></span></article>)}</div>{!shown.length&&<button onClick={()=>{setQ('');setTopic('Все');}}>Сбросить поиск</button>}</section>}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import articles from '../data/articles.json';
|
||||
export function getArticles() { return articles; }
|
||||
export function getArticleBySlug(slug) { return articles.find(a => a.slug === slug); }
|
||||
export function formatDate(date) { return new Intl.DateTimeFormat('ru-RU', {day:'2-digit',month:'long',year:'numeric'}).format(new Date(date)); }
|
||||
export {formatDate} from './dates.mjs';
|
||||
|
||||
export function getArticleSummaries(){return articles.map(({slug,title,date,excerpt,categories,readingMinutes})=>({slug,title,date,excerpt,categories,readingMinutes}));}
|
||||
@@ -0,0 +1,5 @@
|
||||
// Archived publication timestamps are UTC; their UTC calendar days match the
|
||||
// visible source dates and dated permalinks. Never use the build/browser timezone.
|
||||
export function formatDate(date, {day = '2-digit', month = 'long'} = {}) {
|
||||
return new Intl.DateTimeFormat('ru-RU', {day, month, year: 'numeric', timeZone: 'UTC'}).format(new Date(date));
|
||||
}
|
||||
+3
-2
@@ -5,11 +5,12 @@
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"admin:posts": "node ../local-admin/posts-admin.mjs",
|
||||
"build": "node scripts/prepare-publication.mjs && next build",
|
||||
"build": "node scripts/check-dates.mjs && node scripts/prepare-publication.mjs && next build",
|
||||
"audit:articles": "node scripts/audit-quality-batch.mjs",
|
||||
"audit:draft": "node scripts/audit-editorial-draft.mjs",
|
||||
"start": "next start",
|
||||
"check:publication": "node scripts/prepare-publication.mjs"
|
||||
"check:publication": "node scripts/prepare-publication.mjs",
|
||||
"check:dates": "node scripts/check-dates.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "^16.0.0",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"sourceHash": "656da6da3e89c1b5c48d320b192838f3e6e897b31d78a0a420fc99786d9ac31f",
|
||||
"sourceHash": "f4aa72d3c1fed6b79fbf0cdc0ebc815313b48272d905369e8d0ae5c91771a6e5",
|
||||
"articles": 14
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import {execFileSync} from 'node:child_process';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {formatDate} from '../lib/dates.mjs';
|
||||
|
||||
// Source <time> text, datetime and dated permalinks agree on these calendar days.
|
||||
// These near-midnight UTC instants exposed the old host-timezone-dependent day shift.
|
||||
const fixtures = [
|
||||
{instant:'2019-01-12T21:54:18+00:00', long:'12 января 2019 г.', short:'12 янв. 2019 г.'},
|
||||
{instant:'2017-08-25T21:37:08+00:00', long:'25 августа 2017 г.', short:'25 авг. 2017 г.'},
|
||||
{instant:'2017-07-12T23:20:53+00:00', long:'12 июля 2017 г.', short:'12 июл. 2017 г.'},
|
||||
];
|
||||
if (process.argv.includes('--probe')) {
|
||||
console.log(JSON.stringify({hostTimezone:new Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
dates:fixtures.map(({instant})=>({instant,long:formatDate(instant),short:formatDate(instant,{month:'short',day:'numeric'})}))}));
|
||||
} else {
|
||||
const expected=fixtures.map(({instant,long,short})=>({instant,long,short}));
|
||||
const results=['UTC','Europe/Moscow'].map(TZ=>{
|
||||
const result=JSON.parse(execFileSync(process.execPath,[fileURLToPath(import.meta.url),'--probe'],{env:{...process.env,TZ},encoding:'utf8'}));
|
||||
assert.equal(result.hostTimezone,TZ,'Probe must actually use the requested host timezone');
|
||||
assert.deepEqual(result.dates,expected,'Historical publication day must not shift with host/browser timezone');
|
||||
return result;
|
||||
});
|
||||
console.log(JSON.stringify({historicalCalendar:'UTC',fixtures:fixtures.length,hostTimezones:results.map(r=>r.hostTimezone),passed:true}));
|
||||
}
|
||||
Reference in new issue
Block a user