Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
37556399
Commit
37556399
authored
Feb 10, 2019
by
Nick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: use frontmatter format for metadata in storage
parent
0eac7897
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
51 deletions
+26
-51
Makefile
Makefile
+1
-1
pages.js
server/models/pages.js
+21
-0
storage.js
server/modules/storage/disk/storage.js
+2
-25
storage.js
server/modules/storage/git/storage.js
+2
-25
No files found.
Makefile
View file @
37556399
...
...
@@ -24,7 +24,7 @@ test: ## Run code linting tests
pug-lint server/views
&&
jest
docker-dev-up
:
##
Run dockerized dev environment
docker-compose
-f
./dev/docker-
${
DEVDB
}
/docker-compose.yml
-p
wiki
--project-directory
.
up
-d
docker-compose
-f
./dev/docker-
${
DEVDB
}
/docker-compose.yml
-p
wiki
--project-directory
.
up
-d
--remove-orphans
docker-compose
-f
./dev/docker-
${
DEVDB
}
/docker-compose.yml
-p
wiki
--project-directory
.
exec
wiki yarn dev
docker-dev-down
:
##
Shutdown dockerized dev environment
...
...
server/models/pages.js
View file @
37556399
...
...
@@ -114,6 +114,27 @@ module.exports = class Page extends Model {
})
}
/**
* Inject page metadata into contents
*/
injectMetadata
()
{
let
meta
=
[
[
'title'
,
this
.
title
],
[
'description'
,
this
.
description
],
[
'published'
,
this
.
isPublished
.
toString
()],
[
'date'
,
this
.
updatedAt
],
[
'tags'
,
''
]
]
switch
(
this
.
contentType
)
{
case
'markdown'
:
return
'---
\
n'
+
meta
.
map
(
mt
=>
`
${
mt
[
0
]}
:
${
mt
[
1
]}
`
).
join
(
'
\
n'
)
+
'
\
n---
\
n
\
n'
+
this
.
content
case
'html'
:
return
'<!--
\
n'
+
meta
.
map
(
mt
=>
`
${
mt
[
0
]}
:
${
mt
[
1
]}
`
).
join
(
'
\
n'
)
+
'
\
n-->
\
n
\
n'
+
this
.
content
default
:
return
this
.
content
}
}
static
async
createPage
(
opts
)
{
await
WIKI
.
models
.
pages
.
query
().
insert
({
authorId
:
opts
.
authorId
,
...
...
server/modules/storage/disk/storage.js
View file @
37556399
...
...
@@ -15,29 +15,6 @@ const getFileExtension = (contentType) => {
}
}
/**
* Inject page metadata into contents
*/
const
injectMetadata
=
(
page
)
=>
{
let
meta
=
[
[
'title'
,
page
.
title
],
[
'description'
,
page
.
description
]
]
let
metaFormatted
=
''
switch
(
page
.
contentType
)
{
case
'markdown'
:
metaFormatted
=
meta
.
map
(
mt
=>
`[//]: #
${
mt
[
0
]}
:
${
mt
[
1
]}
`
).
join
(
'
\
n'
)
break
case
'html'
:
metaFormatted
=
meta
.
map
(
mt
=>
`<!--
${
mt
[
0
]}
:
${
mt
[
1
]}
-->`
).
join
(
'
\
n'
)
break
default
:
metaFormatted
=
meta
.
map
(
mt
=>
`#WIKI
${
mt
[
0
]}
:
${
mt
[
1
]}
`
).
join
(
'
\
n'
)
break
}
return
`
${
metaFormatted
}
\n\n
${
page
.
content
}
`
}
module
.
exports
=
{
async
activated
()
{
// not used
...
...
@@ -56,12 +33,12 @@ module.exports = {
async
created
(
page
)
{
WIKI
.
logger
.
info
(
`(STORAGE/DISK) Creating file
${
page
.
path
}
...`
)
const
filePath
=
path
.
join
(
this
.
config
.
path
,
`
${
page
.
path
}
.
${
getFileExtension
(
page
.
contentType
)}
`
)
await
fs
.
outputFile
(
filePath
,
injectMetadata
(
page
),
'utf8'
)
await
fs
.
outputFile
(
filePath
,
page
.
injectMetadata
(
),
'utf8'
)
},
async
updated
(
page
)
{
WIKI
.
logger
.
info
(
`(STORAGE/DISK) Updating file
${
page
.
path
}
...`
)
const
filePath
=
path
.
join
(
this
.
config
.
path
,
`
${
page
.
path
}
.
${
getFileExtension
(
page
.
contentType
)}
`
)
await
fs
.
outputFile
(
filePath
,
injectMetadata
(
page
),
'utf8'
)
await
fs
.
outputFile
(
filePath
,
page
.
injectMetadata
(
),
'utf8'
)
},
async
deleted
(
page
)
{
WIKI
.
logger
.
info
(
`(STORAGE/DISK) Deleting file
${
page
.
path
}
...`
)
...
...
server/modules/storage/git/storage.js
View file @
37556399
...
...
@@ -17,29 +17,6 @@ const getFileExtension = (contentType) => {
}
}
/**
* Inject page metadata into contents
*/
const
injectMetadata
=
(
page
)
=>
{
let
meta
=
[
[
'title'
,
page
.
title
],
[
'description'
,
page
.
description
]
]
let
metaFormatted
=
''
switch
(
page
.
contentType
)
{
case
'markdown'
:
metaFormatted
=
meta
.
map
(
mt
=>
`[//]: #
${
mt
[
0
]}
:
${
mt
[
1
]}
`
).
join
(
'
\
n'
)
break
case
'html'
:
metaFormatted
=
meta
.
map
(
mt
=>
`<!--
${
mt
[
0
]}
:
${
mt
[
1
]}
-->`
).
join
(
'
\
n'
)
break
default
:
metaFormatted
=
meta
.
map
(
mt
=>
`#WIKI
${
mt
[
0
]}
:
${
mt
[
1
]}
`
).
join
(
'
\
n'
)
break
}
return
`
${
metaFormatted
}
\n\n
${
page
.
content
}
`
}
module
.
exports
=
{
git
:
null
,
repoPath
:
path
.
join
(
process
.
cwd
(),
'data/repo'
),
...
...
@@ -131,7 +108,7 @@ module.exports = {
WIKI
.
logger
.
info
(
`(STORAGE/GIT) Committing new file
${
page
.
path
}
...`
)
const
fileName
=
`
${
page
.
path
}
.
${
getFileExtension
(
page
.
contentType
)}
`
const
filePath
=
path
.
join
(
this
.
repoPath
,
fileName
)
await
fs
.
outputFile
(
filePath
,
injectMetadata
(
page
),
'utf8'
)
await
fs
.
outputFile
(
filePath
,
page
.
injectMetadata
(
),
'utf8'
)
await
this
.
git
.
add
(
`./
${
fileName
}
`
)
await
this
.
git
.
commit
(
`docs: create
${
page
.
path
}
`
,
fileName
,
{
...
...
@@ -142,7 +119,7 @@ module.exports = {
WIKI
.
logger
.
info
(
`(STORAGE/GIT) Committing updated file
${
page
.
path
}
...`
)
const
fileName
=
`
${
page
.
path
}
.
${
getFileExtension
(
page
.
contentType
)}
`
const
filePath
=
path
.
join
(
this
.
repoPath
,
fileName
)
await
fs
.
outputFile
(
filePath
,
injectMetadata
(
page
),
'utf8'
)
await
fs
.
outputFile
(
filePath
,
page
.
injectMetadata
(
),
'utf8'
)
await
this
.
git
.
add
(
`./
${
fileName
}
`
)
await
this
.
git
.
commit
(
`docs: update
${
page
.
path
}
`
,
fileName
,
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment