#45 API ぼちぼち
This commit is contained in:
@@ -49,4 +49,22 @@ class WikiPagesController < ApplicationController
|
||||
|
||||
render json: q.limit(20)
|
||||
end
|
||||
|
||||
def changes
|
||||
id = params[:id]
|
||||
log = id.present? ? wiki.page("#{ id }.md").versions : wiki.repo.log('main', nil, max_count: 50)
|
||||
render json: log.map { |commit|
|
||||
{ sha: commit.id,
|
||||
author: commit.author.name,
|
||||
message: commit.message,
|
||||
timestamp: commit.authored_date } }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
WIKI_PATH = Rails.root.join('wiki').to_s
|
||||
|
||||
def wiki
|
||||
@wiki ||= Gollum::Wiki.new(WIKI_PATH)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,6 +6,7 @@ Rails.application.routes.draw do
|
||||
get 'preview/thumbnail', to: 'preview#thumbnail'
|
||||
get 'wiki/title/:title', to: 'wiki_pages#show_by_title'
|
||||
get 'wiki/search', to: 'wiki_pages#search'
|
||||
get 'wiki/changes', to: 'wiki_pages#changes'
|
||||
get 'wiki/:id', to: 'wiki_pages#show'
|
||||
post 'wiki', to: 'wiki_pages#create'
|
||||
put 'wiki/:id', to: 'wiki_pages#update'
|
||||
|
||||
@@ -11,6 +11,7 @@ import WikiPage from '@/pages/WikiPage'
|
||||
import WikiNewPage from '@/pages/WikiNewPage'
|
||||
import WikiEditPage from '@/pages/WikiEditPage'
|
||||
import WikiDetailPage from '@/pages/WikiDetailPage'
|
||||
import WikiHistoryPage from '@/pages/WikiHistoryPage'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import axios from 'axios'
|
||||
import { Toaster } from '@/components/ui/toaster'
|
||||
@@ -66,6 +67,7 @@ export default () => {
|
||||
<Route path="/wiki/:name" element={<WikiDetailPage />} />
|
||||
<Route path="/wiki/new" element={<WikiNewPage />} />
|
||||
<Route path="/wiki/:id/edit" element={<WikiEditPage />} />
|
||||
<Route path="/wiki/changes" element={<WikiHistoryPage />} />
|
||||
</Routes>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -130,7 +130,7 @@ const TopNav: React.FC = ({ user, setUser }: Props) => {
|
||||
<>
|
||||
<Separator />
|
||||
<Link to={`/posts?tags=${ location.pathname.split ('/')[2] }`} className={subClass}>投稿</Link>
|
||||
<Link to={`/wiki/${ wikiId || location.pathname.split ('/')[2] }/history`} className={subClass}>履歴</Link>
|
||||
<Link to={`/wiki/changes?id=${ wikiId }`} className={subClass}>履歴</Link>
|
||||
<Link to={`/wiki/${ wikiId || location.pathname.split ('/')[2] }/edit`} className={subClass}>編輯</Link>
|
||||
</>}
|
||||
</div>)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import MainArea from '@/components/layout/MainArea'
|
||||
|
||||
|
||||
export default () => {
|
||||
return (
|
||||
<MainArea>
|
||||
</MainArea>)
|
||||
}
|
||||
Reference in New Issue
Block a user