From a959934b41db0c67fd0e9d85c0eaf675d722a9f7 Mon Sep 17 00:00:00 2001 From: "MD. MOHIBUR RAHMAN" <35300157+mrpmohiburrahman@users.noreply.github.com> Date: Sat, 29 Jun 2024 06:05:41 +0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20add=20precommit=20for=20getting?= =?UTF-8?q?=20last=20updated=20time=20based=20on=20lates=20commit=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .husky/pre-commit | 1 + components/last_updated/LastUpdated.tsx | 10 +++------- package.json | 5 ++++- pnpm-lock.yaml | 10 ++++++++++ scripts/lastCommitDate.json | 3 +++ scripts/updateLastCommitDate.js | 13 +++++++++++++ 6 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 .husky/pre-commit create mode 100644 scripts/lastCommitDate.json create mode 100644 scripts/updateLastCommitDate.js diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..f1b52e0 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +pnpm run update:lastcommit && git add scripts/lastCommitDate.json diff --git a/components/last_updated/LastUpdated.tsx b/components/last_updated/LastUpdated.tsx index 5031dde..46f3436 100644 --- a/components/last_updated/LastUpdated.tsx +++ b/components/last_updated/LastUpdated.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from "react"; import { format } from "timeago.js"; - +import data from "../../scripts/lastCommitDate.json"; const LastUpdated: React.FC = () => { const [lastUpdatedMessage, setLastUpdatedMessage] = useState( null @@ -9,12 +9,8 @@ const LastUpdated: React.FC = () => { useEffect(() => { const fetchLastCommitDate = async () => { try { - const response = await fetch( - "https://api.github.com/repos/mrpmohiburrahman/awesome-react-native-ui/commits?per_page=1" - ); - const data = await response.json(); - if (data && data.length > 0) { - const lastCommitDate = new Date(data[0].commit.committer.date); + if (data && data.lastCommitDate) { + const lastCommitDate = new Date(data.lastCommitDate); const formattedDate = format(lastCommitDate); setLastUpdatedMessage(`Last updated: ${formattedDate}`); } diff --git a/package.json b/package.json index eca9aa4..170a9de 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,9 @@ "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy", "serve": "docusaurus serve", - "clear": "docusaurus clear" + "clear": "docusaurus clear", + "update:lastcommit": "node scripts/updateLastCommitDate.js", + "prepare": "husky install" }, "dependencies": { "@docusaurus/core": "^3.3.2", @@ -33,6 +35,7 @@ "devDependencies": { "@docusaurus/module-type-aliases": "3.3.2", "@tsconfig/docusaurus": "^2.0.3", + "husky": "^9.0.11", "typescript": "^5.4.5" }, "browserslist": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cd32844..45b7d68 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -66,6 +66,9 @@ importers: '@tsconfig/docusaurus': specifier: ^2.0.3 version: 2.0.3 + husky: + specifier: ^9.0.11 + version: 9.0.11 typescript: specifier: ^5.4.5 version: 5.4.5 @@ -2679,6 +2682,11 @@ packages: resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} engines: {node: '>=10.17.0'} + husky@9.0.11: + resolution: {integrity: sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw==} + engines: {node: '>=18'} + hasBin: true + iconv-lite@0.4.24: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} @@ -8292,6 +8300,8 @@ snapshots: human-signals@2.1.0: {} + husky@9.0.11: {} + iconv-lite@0.4.24: dependencies: safer-buffer: 2.1.2 diff --git a/scripts/lastCommitDate.json b/scripts/lastCommitDate.json new file mode 100644 index 0000000..229e4be --- /dev/null +++ b/scripts/lastCommitDate.json @@ -0,0 +1,3 @@ +{ + "lastCommitDate": "2024-06-29T00:05:41.692Z" +} \ No newline at end of file diff --git a/scripts/updateLastCommitDate.js b/scripts/updateLastCommitDate.js new file mode 100644 index 0000000..ad352a8 --- /dev/null +++ b/scripts/updateLastCommitDate.js @@ -0,0 +1,13 @@ +// scripts/updateLastCommitDate.js +const fs = require("fs"); +const path = require("path"); + +const filePath = path.join(__dirname, "lastCommitDate.json"); +const lastCommitDate = new Date().toISOString(); + +const data = { + lastCommitDate, +}; + +fs.writeFileSync(filePath, JSON.stringify(data, null, 2), "utf-8"); +console.log("Last commit date updated:", lastCommitDate);