このコミットが含まれているのは:
2026-06-09 00:35:25 +09:00
コミット 49d42d576a
3個のファイルの変更173行の追加11行の削除
+85 -3
ファイルの表示
@@ -65,6 +65,37 @@ const originalYearOf = (post: Post): number | null => {
}
const originalDateOf = (post: Post): Date | null => {
const value = post.originalCreatedFrom || post.originalCreatedBefore
if (!(value))
return null
const date = new Date (value)
if (Number.isNaN (date.getTime ()))
return null
return date
}
const originalMonthOf = (post: Post): number | null => {
const date = originalDateOf (post)
if (!(date))
return null
return date.getMonth () + 1
}
const originalMonthDayOf = (post: Post): string | null => {
const date = originalDateOf (post)
if (!(date))
return null
return `${ date.getMonth () + 1 }-${ date.getDate () }`
}
const tagQuestionKey = ({ category, name }: { category: string; name: string }): string =>
`${ category }:${ name }`
@@ -78,6 +109,27 @@ const tagFromQuestionKey = (key: string): { category: string; name: string } =>
const nicoTagLabel = (name: string): string => name.replace (/^nico:/, '')
const tagQuestionText = (category: string, label: string): string => {
switch (category)
{
case 'deerjikist':
return `作者・ニジラーとして「${ label }」に関係してゐる?`
case 'meme':
return `元ネタ・ミームとして「${ label }」に関係しさう?`
case 'character':
return `${ label }」といふキャラクターが関係してゐる?`
case 'material':
return `素材として「${ label }」に関係してゐる?`
case 'nico':
return `ニコニコに「${ label }」といふタグが付いてゐる?`
case 'general':
case 'meta':
default:
return `内容として「${ label }」に関係しさう?`
}
}
const questionableTag = (post: Post, key: string): boolean => {
const { category, name } = tagFromQuestionKey (key)
@@ -128,6 +180,14 @@ export const buildGekanatorQuestions = (posts: Post[]): GekanatorQuestion[] => {
posts
.map (originalYearOf)
.filter ((year): year is number => year !== null))
const originalMonths = countBy (
posts
.map (originalMonthOf)
.filter ((month): month is number => month !== null))
const originalMonthDays = countBy (
posts
.map (originalMonthDayOf)
.filter ((monthDay): monthDay is string => monthDay !== null))
const titleLengthMedian = median (posts.map (post => post.title?.length ?? 0))
const usefulEntries = <T extends string | number> (counts: Map<T, number>) =>
@@ -146,9 +206,7 @@ export const buildGekanatorQuestions = (posts: Post[]): GekanatorQuestion[] => {
return {
id: `tag:${ key }`,
text: category === 'nico'
? `ニコニコに「${ label }」といふタグが付いてゐる?`
: `内容として「${ label }」に関係しさう?`,
text: tagQuestionText (category, label),
kind: 'tag' as const,
test: (post: Post) => questionableTag (post, String (key)) }
})
@@ -171,6 +229,28 @@ export const buildGekanatorQuestions = (posts: Post[]): GekanatorQuestion[] => {
kind: 'original_date' as const,
test: (post: Post) => originalYearOf (post) === year }))
const originalMonthQuestions = usefulEntries (originalMonths)
.filter (([, count]) => count >= 2 && count <= Math.max (2, posts.length * .7))
.slice (0, 20)
.map (([month]) => ({
id: `original-month:${ month }`,
text: `オリジナルの投稿月は ${ month } 月?`,
kind: 'original_date' as const,
test: (post: Post) => originalMonthOf (post) === month }))
const originalMonthDayQuestions = usefulEntries (originalMonthDays)
.filter (([, count]) => count >= 2 && count <= Math.max (2, posts.length * .7))
.slice (0, 20)
.map (([monthDay]) => {
const [month, day] = String (monthDay).split ('-')
return {
id: `original-month-day:${ monthDay }`,
text: `オリジナルの投稿日は ${ month }${ day } 日?`,
kind: 'original_date' as const,
test: (post: Post) => originalMonthDayOf (post) === monthDay }
})
const titleQuestions = [
{
id: 'title:long',
@@ -191,6 +271,8 @@ export const buildGekanatorQuestions = (posts: Post[]): GekanatorQuestion[] => {
return [
...sourceQuestions,
...originalYearQuestions,
...originalMonthQuestions,
...originalMonthDayQuestions,
...titleQuestions,
...tagQuestions]
}