Skip to content

Commit

Permalink
fix: timestamp at zero
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 6, 2023
1 parent 43b0a7b commit d26140e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions components/Sentence.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { extractTimestamp } from "../utils/extractTimestamp";
import { extractSentence } from "~/utils/extractSentence";
import { extractTimestamp } from "~/utils/extractTimestamp";

export default function Sentence({
bvId,
Expand All @@ -9,7 +10,7 @@ export default function Sentence({
}) {
const baseUrl = `https://www.bilibili.com/video/${bvId}`;

const matchResult = sentence.match(/\s*(\d+[\.:]\d+)(.*)/);
const matchResult = extractSentence(sentence);
if (matchResult) {
const seconds = matchResult[1];
const { formattedContent, timestamp } = extractTimestamp(matchResult);
Expand Down
3 changes: 2 additions & 1 deletion pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useLocalStorage } from "react-use";
import { useToast } from "~/hooks/use-toast";
import { useSummarize } from "~/hooks/useSummarize";
import { CHECKOUT_URL, RATE_LIMIT_COUNT } from "~/utils/constants";
import { extractSentence } from "~/utils/extractSentence";
import { extractTimestamp } from "~/utils/extractTimestamp";
import Sentence from "../components/Sentence";
import SquigglyLines from "../components/SquigglyLines";
Expand Down Expand Up @@ -99,7 +100,7 @@ export const Home: NextPage = () => {
const summaryArray = summary.split("- ");
const formattedSummary = summaryArray
.map((s) => {
const matchResult = s.match(/\s*(\d+[\.:]\d+)(.*)/);
const matchResult = extractSentence(s);
if (matchResult) {
const { formattedContent, timestamp } = extractTimestamp(matchResult);
return timestamp + formattedContent;
Expand Down
5 changes: 5 additions & 0 deletions utils/extractSentence.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function extractSentence(sentence: string) {
return sentence
.replace("0:", "0.0") // 修复第0秒
.match(/\s*(\d+[\.:]\d+)(.*)/);
}

1 comment on commit d26140e

@vercel
Copy link

@vercel vercel bot commented on d26140e Mar 6, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.