Skip to content

Commit

Permalink
fix(types-time): update build time type (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabertazimi committed Jun 7, 2022
1 parent f2dd652 commit 597dbdf
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import Divider from '@components/Divider';
import Row from '@components/Row';
import SocialButton from '@components/SocialButton';
import { siteConfig, socialList } from '@config';
import type { SiteConfig, SocialType } from '@types';
import type { BuildTime, SiteConfig, SocialType } from '@types';

interface Props {
buildTime: string | number | Date;
buildTime: BuildTime;
author?: string;
socials?: SiteConfig['socials'];
}
Expand Down
2 changes: 1 addition & 1 deletion hooks/useDisqus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect } from 'react';
const loadScript = (url: string) => {
const script = document.createElement('script');
script.src = `${url}/embed.js`;
script.setAttribute('data-timestamp', (+new Date()).toString());
script.setAttribute('data-timestamp', Date.now().toString());
document.body.appendChild(script);
};

Expand Down
4 changes: 2 additions & 2 deletions layouts/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Container, Divider, Footer, Header, MetaHeader } from '@components';
import { Slide } from '@components/Motion';
import type { PostMeta } from '@types';
import type { BuildTime, PostMeta } from '@types';
import type { ReactNode } from 'react';

interface Props {
banner: string;
posts: PostMeta[];
buildTime: string | number | Date;
buildTime: BuildTime;
children: ReactNode;
}

Expand Down
4 changes: 2 additions & 2 deletions layouts/PostLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BackTop, Container, Footer, Header, MetaHeader } from '@components';
import type { PostMeta } from '@types';
import type { BuildTime, PostMeta } from '@types';
import type { ReactNode } from 'react';

interface Props {
banner: string;
posts: PostMeta[];
buildTime: string | number | Date;
buildTime: BuildTime;
children: ReactNode;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/getBuildTime.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { BuildTime } from '@types';

let buildTime = '';

export default function getBuildTime(): string {
export default function getBuildTime(preset?: BuildTime): string {
if (buildTime.length) {
return buildTime;
}

buildTime = new Date().toISOString();
buildTime = new Date(preset ?? Date.now()).toISOString();

return buildTime;
}
4 changes: 2 additions & 2 deletions pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NotFoundResult } from '@components';
import { Layout } from '@layouts';
import { getBuildTime, getPostsMeta } from '@lib';
import type { PostMeta } from '@types';
import type { BuildTime, PostMeta } from '@types';
import type { GetStaticProps } from 'next/types';

interface Props {
buildTime: string | number | Date;
buildTime: BuildTime;
postsMeta: PostMeta[];
}

Expand Down
4 changes: 2 additions & 2 deletions pages/about.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { GithubCard } from '@components';
import { Layout } from '@layouts';
import { getBuildTime, getGitHubData, getPostsMeta } from '@lib';
import type { GitHub, PostMeta } from '@types';
import type { BuildTime, GitHub, PostMeta } from '@types';
import type { GetStaticProps } from 'next/types';

interface Props {
buildTime: string | number | Date;
buildTime: BuildTime;
githubData: GitHub;
postsMeta: PostMeta[];
}
Expand Down
4 changes: 2 additions & 2 deletions pages/books.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BooksGrid } from '@components';
import { Layout } from '@layouts';
import { getBuildTime, getPostsMeta } from '@lib';
import type { PostMeta } from '@types';
import type { BuildTime, PostMeta } from '@types';
import type { GetStaticProps } from 'next/types';

interface Props {
buildTime: string | number | Date;
buildTime: BuildTime;
postsMeta: PostMeta[];
}

Expand Down
4 changes: 2 additions & 2 deletions pages/post/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Article } from '@components';
import { PostLayout } from '@layouts';
import { getBuildTime, getPostData, getPostsMeta } from '@lib';
import type { Post, PostMeta } from '@types';
import type { BuildTime, Post, PostMeta } from '@types';
import 'katex/dist/katex.css';
import type { GetStaticPaths, GetStaticProps } from 'next/types';
import type { ParsedUrlQuery } from 'node:querystring';

interface Props {
buildTime: string | number | Date;
buildTime: BuildTime;
postData: Post;
postsMeta: PostMeta[];
}
Expand Down
4 changes: 2 additions & 2 deletions pages/posts.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PostsGrid } from '@components';
import { Layout } from '@layouts';
import { getBuildTime, getPostsMeta } from '@lib';
import type { PostMeta } from '@types';
import type { BuildTime, PostMeta } from '@types';
import type { GetStaticProps } from 'next/types';

interface Props {
buildTime: string | number | Date;
buildTime: BuildTime;
postsMeta: PostMeta[];
}

Expand Down
4 changes: 2 additions & 2 deletions pages/tag/[tag].tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { PostsList, TagsCloud } from '@components';
import { Layout } from '@layouts';
import { getBuildTime, getPostsMeta, getTagsData } from '@lib';
import type { PostMeta, Tag, Tags } from '@types';
import type { BuildTime, PostMeta, Tag, Tags } from '@types';
import type { GetStaticPaths, GetStaticProps } from 'next/types';
import type { ParsedUrlQuery } from 'node:querystring';

interface Props {
buildTime: string | number | Date;
buildTime: BuildTime;
postsMeta: PostMeta[];
tagsData: Tags;
activeTag: Tag;
Expand Down
4 changes: 2 additions & 2 deletions pages/tags.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PostsList, TagsCloud } from '@components';
import { Layout } from '@layouts';
import { getBuildTime, getPostsMeta, getTagsData } from '@lib';
import type { PostMeta, Tags } from '@types';
import type { BuildTime, PostMeta, Tags } from '@types';
import type { GetStaticProps } from 'next/types';

interface Props {
buildTime: string | number | Date;
buildTime: BuildTime;
postsMeta: PostMeta[];
tagsData: Tags;
}
Expand Down
2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { MDXRemoteSerializeResult } from 'next-mdx-remote';

export declare type BuildTime = string | number | Date;

export declare type Tag = string;
export declare type Tags = Record<Tag, number>;

Expand Down

1 comment on commit 597dbdf

@vercel
Copy link

@vercel vercel bot commented on 597dbdf Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blog – ./

blog.tazimi.dev
blog-sabertaz.vercel.app
blog-git-main-sabertaz.vercel.app

Please sign in to comment.