summaryrefslogtreecommitdiff
path: root/src/app/_components/archiveLinkElement.tsx
blob: d97d90447e572f9d159a207cfd5502c9b2e6e9aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import Link from "next/link";
type ArticlePage = {
  type: "article",
  articleId: number,
  subPageNumber?: number,
}
type AnimeTop = {
  type: "animeTop",
  animeId: number,
};
type AnimeReviewList = {
  type: "animeReviewList",
  animeId: number,
  /** 0始まり */
  pageNumber: number,
};
type AnimeReviewItem = {
  type: "AnimeReviewItem",
  animeId: number,
  reviewId: number,
};
type Common = { showLinkUnderline?: boolean }
type Option = (ArticlePage | AnimeTop | AnimeReviewList | AnimeReviewItem) & Common;
export function ArciveLinkElement(option: Option) {
  const officialLinkTitle = `公式のakiba-souken.com へのリンク。閉鎖後は繋がらなくなるはず`;
  const iaSearchResultLinkTitle = `InternetArchive の検索結果へのリンク`;
  const iframeLinkTitle = `Iframeを使ってInternetArchiveに記録されたアーカイブを表示します`;
  let originalUrl = "";
  let iframeSrc = "";
  let suffixPrivate: JSX.Element = <></>;
  let className = "";
  if (option.type == "article") {
    if (option.subPageNumber == null) {
      originalUrl = `https://akiba-souken.com/article/${option.articleId}/`;
      iframeSrc = `article-${option.articleId}`;
    } else {
      originalUrl = `https://akiba-souken.com/article/${option.articleId}/?page=${option.subPageNumber}`;
      iframeSrc = `article-${option.articleId}-${option.subPageNumber}`;
      suffixPrivate = <>Page:{option.subPageNumber}</>
    }
  } else if (option.type == "animeTop") {
    originalUrl = `https://akiba-souken.com/anime/${option.animeId}/`;
    iframeSrc = `anime-${option.animeId}`
  } else if (option.type == "animeReviewList") {
    if (option.pageNumber == 0) {
      originalUrl = `https://akiba-souken.com/anime/${option.animeId}/review/`;
      iframeSrc = `anime-${option.animeId}-review`
    } else {
      const page = option.pageNumber + 1;
      originalUrl = `https://akiba-souken.com/anime/${option.animeId}/?page=${page}`;
      iframeSrc = `anime-${option.animeId}-review-p${page}`
    }
  } else if (option.type == "AnimeReviewItem") {
    originalUrl = `https://akiba-souken.com/anime/${option.animeId}/review/${option.reviewId}`;
    iframeSrc = `anime-${option.animeId}-review-${option.reviewId}`;
  } else {
    throw new Error();
  }
  if (option.showLinkUnderline == true) {
    className = `original-href`;
  }
  return (
    <>
      <a
        href={originalUrl}
        target="_blank"
        className={`transition duration-300 ease-in-out hover:text-gray-900 ${className}`}
        title={officialLinkTitle}
      >公式</a>
      <a
        href={`https://web.archive.org/web/*/${originalUrl}`}
        target="_blank"
        className={`transition duration-300 ease-in-out hover:text-gray-900 ${className}`}
        title={iaSearchResultLinkTitle}
      >IA検索結果</a>
      <Link
        href={`/iframe?src=${iframeSrc}`}
        className={`transition duration-300 ease-in-out hover:text-gray-900 ${className}`}
        title={iframeLinkTitle}
      >IAをiframe</Link>
      {suffixPrivate}
    </>
  )
}