Skip to content

Commit 67e5a8e

Browse files
committed
feat: support private sections on public pages
1 parent df6dd00 commit 67e5a8e

File tree

9 files changed

+26
-14
lines changed

9 files changed

+26
-14
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Tool to export raw [Logseq](https://github.com/logseq/logseq) Markdown pages (wi
44

55
- Takes Logseq page properties (`title:: Hello world`) and turns them into [Front Matter properties](https://gohugo.io/content-management/front-matter/) `title: Hello World`.
66
- Changes the Markdown syntax to remove the top-level bullet points.
7+
- if you have top-level block `- private` in your file, `logseq-export` will remove it and all content that follows. I use it for copyrighted content like verbatim highlights/pictures from books.
78

89
See an **example of a deployed graph** on [viktomas.github.io/logseq-export](https://viktomas.github.io/logseq-export/). The graph and the [Hugo](https://gohugo.io/) project can be found in the [example](/example/) folder. Run the example locally with ``
910

@@ -86,7 +87,7 @@ export BLOG_IMAGES_FOLDER="/assets/graph"
8687

8788
## From
8889

89-
![logseq test page](./docs/assets/logseq-teset-page.png)
90+
![logseq test page](./docs/assets/logseq-teset-page-2.png)
9091

9192
## To
9293

19.5 KB
Loading

docs/assets/logseq-teset-page.png

-14.9 KB
Binary file not shown.

example/logseq-export-example/content/graph/2022-09-25-test-page.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ title: "Test page"
66
---
77

88
This is an example paragraph
9-
109
- Second level means bullet points
1110
- `logseq-export` also supports multi-level bullet points
1211

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module github.com/viktomas/logseq-export
33
go 1.19
44

55
require (
6-
github.com/spf13/afero v1.9.2
7-
github.com/stretchr/testify v1.8.1
8-
golang.org/x/exp v0.0.0-20220921164117-439092de6870
9-
github.com/knadh/koanf/v2 v2.0.1
106
github.com/knadh/koanf/parsers/yaml v0.1.0
117
github.com/knadh/koanf/providers/basicflag v0.1.0
128
github.com/knadh/koanf/providers/file v0.1.0
9+
github.com/knadh/koanf/v2 v2.0.1
10+
github.com/spf13/afero v1.9.2
11+
github.com/stretchr/testify v1.8.1
12+
golang.org/x/exp v0.0.0-20220921164117-439092de6870
1313
)
1414

1515
require (

go.sum

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
123123
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
124124
github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs=
125125
github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI=
126-
github.com/knadh/koanf/parsers/toml v0.1.0 h1:S2hLqS4TgWZYj4/7mI5m1CQQcWurxUz6ODgOub/6LCI=
127-
github.com/knadh/koanf/parsers/toml v0.1.0/go.mod h1:yUprhq6eo3GbyVXFFMdbfZSo928ksS+uo0FFqNMnO18=
128126
github.com/knadh/koanf/parsers/yaml v0.1.0 h1:ZZ8/iGfRLvKSaMEECEBPM1HQslrZADk8fP1XFUxVI5w=
129127
github.com/knadh/koanf/parsers/yaml v0.1.0/go.mod h1:cvbUDC7AL23pImuQP0oRw/hPuccrNBS2bps8asS0CwY=
130128
github.com/knadh/koanf/providers/basicflag v0.1.0 h1:NZwVblBNHBUrjzk+rqY1TlBC6ariah0lj4iotjZRUYs=
@@ -145,8 +143,6 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
145143
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
146144
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
147145
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
148-
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
149-
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
150146
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
151147
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
152148
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -162,7 +158,6 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
162158
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
163159
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
164160
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
165-
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
166161
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
167162
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
168163
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=

parse.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ func removeTabFromMultiLevelBulletPoints(from string) string {
109109
})
110110
}
111111

112+
// finds first `- private` top level bullet point in the document and removes it and everything
113+
// that follows to the end of file
114+
func removePrivateContent(from string) string {
115+
return regexp.MustCompile(`(?m:^- private.*$[\s\S]*)$`).ReplaceAllString(from, "")
116+
}
117+
112118
const multilineBlocks = `\n?(- .*\n(?: .*\n?)+)`
113119

114120
/*
@@ -146,6 +152,7 @@ func parseContent(rawContent string) parsedContent {
146152
content := applyStringTransformers(rawContent,
147153
stripAttributes,
148154
removeEmptyBulletPoints,
155+
removePrivateContent,
149156
unindentMultilineStrings,
150157
firstBulletPointsToParagraphs,
151158
// since we turned the first bullet points to paragraphs

parse_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,17 @@ lines
213213
in
214214
one`, result.content)
215215
})
216+
217+
t.Run("removes all content after - private", func(t *testing.T) {
218+
result := parseContent(`
219+
- single line
220+
- private
221+
- multiple
222+
lines
223+
in
224+
one`)
225+
require.Equal(t, `
226+
single line
227+
`, result.content)
228+
})
216229
}

run_example.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)