Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
include "com.enonic.xp:lib-value:${xpVersion}"
include "no.item:lib-xp-cristin:1.3.2"
include "no.item:lib-xp-time:1.0.4"
include "com.enonic.lib:lib-markdown:1.0.0"
}

repositories {
Expand Down
2 changes: 0 additions & 2 deletions nais.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ spec:
requests:
memory: 2Gi

ttl: 168h

prometheus:
enabled: false

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ declare global {
export type LocalSearch = _PartComponent<'mimir:localSearch'>
export type MailChimpForm = _PartComponent<'mimir:mailChimpForm'>
export type Map = _PartComponent<'mimir:map'>
export type Markdown = _PartComponent<'mimir:markdown'>
export type Maths = _PartComponent<'mimir:maths'>
export type MenuBox = _PartComponent<'mimir:menuBox'>
export type MenuDropdown = _PartComponent<'mimir:menuDropdown'>
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/lib/ssb/utils/markdownUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { connect, type RepoConnection } from '/lib/xp/node'

export function connectMarkdownRepo(): RepoConnection {
return connect({
repoId: 'no.ssb.pubmd',
branch: 'master',
principals: ['role:system.admin'],
})
}
30 changes: 30 additions & 0 deletions src/main/resources/services/getMarkdownNodes/getMarkdownNodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { connectMarkdownRepo } from '/lib/ssb/utils/markdownUtils'

export const get = (): XP.Response => {
const conn = connectMarkdownRepo()

const markdownNodes = conn.findChildren({
parentKey: '/',
count: 100,
})

const hits = markdownNodes.hits.map((hit) => {
const node = conn.get(hit.id)
return {
id: hit.id,
displayName: node.displayName,
}
})

const body = {
count: markdownNodes.count,
total: markdownNodes.total,
hits: hits,
}

return {
status: 200,
body: body,
contentType: 'application/json',
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<service>
<allow>
<principal>role:system.everyone</principal>
</allow>
</service>
30 changes: 30 additions & 0 deletions src/main/resources/services/postMarkdown/postMarkdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { connectMarkdownRepo } from '/lib/ssb/utils/markdownUtils'

export const post = (req: XP.Request): XP.Response => {
const setFields = (obj) => {
obj.displayName = req.params.displayName
obj.markdown = req.params.markdown
return obj
}

const conn = connectMarkdownRepo()

const nodeId = typeof req.params._id === 'string' ? req.params._id : ''
const nodeExists = nodeId ? conn.exists(nodeId) : false

let result
if (nodeExists) {
result = conn.modify({
key: nodeId,
editor: setFields,
})
} else {
const createContentParams = setFields({})
result = conn.create(createContentParams)
}

return {
status: 200,
body: result,
}
}
5 changes: 5 additions & 0 deletions src/main/resources/services/postMarkdown/postMarkdown.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<service>
<allow>
<principal>role:system.everyone</principal>
</allow>
</service>
19 changes: 19 additions & 0 deletions src/main/resources/site/parts/markdown/markdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { getComponent } from '/lib/xp/portal'
import { connectMarkdownRepo } from '/lib/ssb/utils/markdownUtils'
import { render } from '/lib/enonic/react4xp'
import { render as renderMarkdown } from '/lib/markdown'

export function get(req: XP.Request): XP.Response {
const component = getComponent<XP.PartComponent.Markdown>()

const conn = connectMarkdownRepo()

const nodeId = component.config.markdownNode
const node = conn.get(nodeId)
const markdownText = node.markdown

const props = {
markdownTextRendered: renderMarkdown(markdownText),
}
return render(component, props, req)
}
9 changes: 9 additions & 0 deletions src/main/resources/site/parts/markdown/markdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'

export default (props) => (
<div
dangerouslySetInnerHTML={{
__html: props.markdownTextRendered,
}}
/>
)
15 changes: 15 additions & 0 deletions src/main/resources/site/parts/markdown/markdown.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<part>
<display-name>Markdown</display-name>
<description></description>
<form>
<input name="markdownNode" type="CustomSelector">
<label>Markdown-node</label>
<occurrences minimum="0" maximum="1"/>
<config>
<service>getMarkdownNodes</service>
</config>
</input>
</form>

</part>
Loading