Skip to content

Commit

Permalink
fix parse blog page url issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
mazzzystar committed Oct 4, 2024
1 parent 1a0897d commit 291bbc5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/blog/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export default function BlogPost({ params }: { params: { id: string } }) {

try {
// Use the encoded ID directly from the params
const encodedId = params.id;
// Decode the ID before sending it to the API
const response = await fetch(
`/api/github?action=getBlogPost&id=${encodedId}`
`/api/github?action=getBlogPost&id=${params.id}`
);
if (!response.ok) {
throw new Error("Failed to fetch blog post");
Expand Down
1 change: 1 addition & 0 deletions components/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import React from "react";
import { useState, useEffect, useCallback } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import { Button } from "@/components/ui/button";
Expand Down
5 changes: 1 addition & 4 deletions lib/githubApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,11 @@ export async function getBlogPost(id: string, accessToken: string): Promise<Blog
const { owner, repo } = await getRepoInfo(accessToken);

try {
// Encode the ID to match the file name format
const encodedId = encodeURIComponent(id).replace(/%20/g, '-');

// Fetch the file content
const contentResponse = await octokit.repos.getContent({
owner,
repo,
path: `content/blog/${encodedId}.md`,
path: `content/blog/${decodeURIComponent(id)}.md`,
});

if (Array.isArray(contentResponse.data) || !('content' in contentResponse.data)) {
Expand Down

0 comments on commit 291bbc5

Please sign in to comment.