Render/Manage Blog using Github's Issue.
-
Put a .env file in the root of the project with the following environment variables
變數 說明 GITHUB_CLIENT_ID Client ID provided by GitHub when registing a OAUTH App GITHUB_CLIENT_SECRET Client Secret provided by GitHub when registing a OAUTH App GITHUB_UNAUTHENTICATED_TOKEN A Fine-grained personal access tokens for unauthenticated to access blogger GITHUB_ISSUE_BLOGGER_USERNAME The owner of the repo GITHUB_ISSUE_BLOGGER_REPO_NAME The repo used as Blogger -
Run at root of project
npm run dev
-
Open the site
http://localhost:3000
- / : Root. List the post.
- /viewer : Viewer. View the sepicific post. Viewer is a modal over on List.
- /editor : Post Editor. Editor for creating/modifing postes. Editor is a modal over on List.
- /login : Login page. The page is used to validate if the user login sucessfully.
- Modal is a slot of next.js layout
The directory provide some shared component/helper.
-
Server part:
- Github (utils/github.ts) : Interactive with Github REST API (Get AccessToken, Load Issue, Update Issue, etc)
- ErrorHandler (utils/errorHandlerServer.ts) : Each function provided by server should return corresponed status code and message. The unexpected error is hidden from return message.
-
UI part (include server component):
- LoginState (utils/LoginStateContext.tsx) : Store the login state (is user login ?, is user is owner of the viewed repo) globally
- BloggerList (utils/BloggerListContext.tsx) : Global
post
manager (List, Update, Delete, etc) - / (page.tsx): List the post information stored in BloggerListContext.
- /viewer (@modal/viewer/page.tsx): Viewer. Download post title/body from server
- /editor (@modal/editor/page.tsx): Post Editor. Validate length of title/body before sent to server
- /login (login/page.tsx): Login page. Redirect to Github when no valid
access_token
/code
. Getaccess_token
if hascode
in URLSearchParames. Validateaccess_token
when present in cookies. - ErrorHandler (utils/errorHandlerClient.ts) : Handle the response from server. Redirect/Get response data according to the status code.