Skip to content

Commit

Permalink
feat: support private sections on public pages
Browse files Browse the repository at this point in the history
  • Loading branch information
viktomas committed May 3, 2024
1 parent df6dd00 commit 67e5a8e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Tool to export raw [Logseq](https://github.com/logseq/logseq) Markdown pages (wi

- Takes Logseq page properties (`title:: Hello world`) and turns them into [Front Matter properties](https://gohugo.io/content-management/front-matter/) `title: Hello World`.
- Changes the Markdown syntax to remove the top-level bullet points.
- 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.

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 ``

Expand Down Expand Up @@ -86,7 +87,7 @@ export BLOG_IMAGES_FOLDER="/assets/graph"

## From

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

## To

Expand Down
Binary file added docs/assets/logseq-teset-page-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/assets/logseq-teset-page.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ title: "Test page"
---

This is an example paragraph

- Second level means bullet points
- `logseq-export` also supports multi-level bullet points

Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/viktomas/logseq-export
go 1.19

require (
github.com/spf13/afero v1.9.2
github.com/stretchr/testify v1.8.1
golang.org/x/exp v0.0.0-20220921164117-439092de6870
github.com/knadh/koanf/v2 v2.0.1
github.com/knadh/koanf/parsers/yaml v0.1.0
github.com/knadh/koanf/providers/basicflag v0.1.0
github.com/knadh/koanf/providers/file v0.1.0
github.com/knadh/koanf/v2 v2.0.1
github.com/spf13/afero v1.9.2
github.com/stretchr/testify v1.8.1
golang.org/x/exp v0.0.0-20220921164117-439092de6870
)

require (
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs=
github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI=
github.com/knadh/koanf/parsers/toml v0.1.0 h1:S2hLqS4TgWZYj4/7mI5m1CQQcWurxUz6ODgOub/6LCI=
github.com/knadh/koanf/parsers/toml v0.1.0/go.mod h1:yUprhq6eo3GbyVXFFMdbfZSo928ksS+uo0FFqNMnO18=
github.com/knadh/koanf/parsers/yaml v0.1.0 h1:ZZ8/iGfRLvKSaMEECEBPM1HQslrZADk8fP1XFUxVI5w=
github.com/knadh/koanf/parsers/yaml v0.1.0/go.mod h1:cvbUDC7AL23pImuQP0oRw/hPuccrNBS2bps8asS0CwY=
github.com/knadh/koanf/providers/basicflag v0.1.0 h1:NZwVblBNHBUrjzk+rqY1TlBC6ariah0lj4iotjZRUYs=
Expand All @@ -145,8 +143,6 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -162,7 +158,6 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
Expand Down
7 changes: 7 additions & 0 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func removeTabFromMultiLevelBulletPoints(from string) string {
})
}

// finds first `- private` top level bullet point in the document and removes it and everything
// that follows to the end of file
func removePrivateContent(from string) string {
return regexp.MustCompile(`(?m:^- private.*$[\s\S]*)$`).ReplaceAllString(from, "")
}

const multilineBlocks = `\n?(- .*\n(?: .*\n?)+)`

/*
Expand Down Expand Up @@ -146,6 +152,7 @@ func parseContent(rawContent string) parsedContent {
content := applyStringTransformers(rawContent,
stripAttributes,
removeEmptyBulletPoints,
removePrivateContent,
unindentMultilineStrings,
firstBulletPointsToParagraphs,
// since we turned the first bullet points to paragraphs
Expand Down
13 changes: 13 additions & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,17 @@ lines
in
one`, result.content)
})

t.Run("removes all content after - private", func(t *testing.T) {
result := parseContent(`
- single line
- private
- multiple
lines
in
one`)
require.Equal(t, `
single line
`, result.content)
})
}
3 changes: 0 additions & 3 deletions run_example.sh

This file was deleted.

0 comments on commit 67e5a8e

Please sign in to comment.