Skip to content

Commit

Permalink
Make thread colors optional
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickDeVries committed Nov 21, 2023
1 parent 49b4e3c commit b2883ae
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 69 deletions.
110 changes: 55 additions & 55 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Publish Plugin

on:
workflow_dispatch:
workflow_dispatch:
push:
tags:
- "*"
- '*'

env:
PLUGIN_NAME: logseq-plugin-colored-threads
Expand All @@ -14,61 +14,61 @@ jobs:
name: Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x
- uses: actions/checkout@v3
- name: Set Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Run install
uses: borales/[email protected]
with:
cmd: install # will run `yarn install` command
- name: Run install
uses: borales/[email protected]
with:
cmd: install # will run `yarn install` command

- name: Build package bundle
uses: borales/[email protected]
with:
cmd: build # will run `yarn build` command

- name: Zip build
id: zip
run: |
mv dist ${{ env.PLUGIN_NAME }}
cp example.png settings.png logo.svg README.md package.json ${{ env.PLUGIN_NAME }}
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
tar -cvzf ${{ env.PLUGIN_NAME }}.tgz ${{ env.PLUGIN_NAME }}
ls
echo "::set-output name=tag_name::$(git tag --sort version:refname | tail -n 1)"
- name: Build package bundle
uses: borales/[email protected]
with:
cmd: build # will run `yarn build` command

- name: Create Release
uses: ncipollo/release-action@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ github.ref }}
with:
allowUpdates: true
draft: false
prerelease: false
- name: Zip build
id: zip
run: |
mv dist ${{ env.PLUGIN_NAME }}
cp example.png settings.png logo.svg README.md package.json ${{ env.PLUGIN_NAME }}
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
tar -cvzf ${{ env.PLUGIN_NAME }}.tgz ${{ env.PLUGIN_NAME }}
ls
echo "::set-output name=tag_name::$(git tag --sort version:refname | tail -n 1)"
- name: Upload zip file
id: upload_zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.PLUGIN_NAME }}.zip
asset_name: ${{ env.PLUGIN_NAME }}-${{ github.ref }}.zip
asset_content_type: application/zip
- name: Create Release
uses: ncipollo/release-action@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ github.ref }}
with:
allowUpdates: true
draft: false
prerelease: false

- name: Upload package.json
id: upload_metadata
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./package.json
asset_name: package.json
asset_content_type: application/json
- name: Upload zip file
id: upload_zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.PLUGIN_NAME }}.zip
asset_name: ${{ env.PLUGIN_NAME }}-${{ github.ref }}.zip
asset_content_type: application/zip

- name: Upload package.json
id: upload_metadata
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./package.json
asset_name: package.json
asset_content_type: application/json
Binary file modified settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 22 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { logseq as PL } from '../package.json'
const onSettingsChange = () => {
const colors: string[] = logseq.settings?.colors.split(',')
const maxDepth: number = logseq.settings?.maxDepth
const shouldColorThreads: boolean = logseq.settings?.shouldColorThreads
const shouldFillBars: boolean = logseq.settings?.shouldFillBars
const shouldColorBullets: boolean = logseq.settings?.shouldColorBullets

Expand All @@ -16,26 +17,24 @@ const onSettingsChange = () => {
const varsString = vars.map(pair => pair.join(': ') + ';').join('\n')
providedStyles = `:root { ${varsString} }`

const threadColorStyles = Array.from(
{ length: maxDepth },
(_, i) => `
.ls-block[level="${i + 1}"] .block-children {
if (shouldColorThreads) {
const threadColorStyles = Array.from(
{ length: maxDepth },
(_, i) => `
.ls-block[level="${i + 1}"] > .block-children-container > .block-children {
border-left-color: var(--block-thread-color-level-${(i % colors.length) + 1});
}
.ls-block[level="${i + 1}"] .block-children-left-border::after {
background-color: var(--block-thread-color-level-${(i % colors.length) + 1});
}
`,
).join('\n')
providedStyles = `
).join('\n')
providedStyles = `
${providedStyles}
${threadColorStyles}
`
`
}

if (shouldFillBars) {
const fillBarsStyles = `
.block-children-left-border::after {
.block-children-left-border::before {
content: '';
position: absolute;
left: 2px;
Expand All @@ -48,7 +47,9 @@ const onSettingsChange = () => {
${Array.from(
{ length: maxDepth },
(_, i) => `
.ls-block[level="${i + 1}"] .block-children-left-border::after {
.ls-block[level="${
i + 1
}"] > .block-children-container > .block-children-left-border::before {
background-color: var(--block-thread-color-level-${(i % colors.length) + 1});
}
`,
Expand Down Expand Up @@ -78,7 +79,7 @@ const onSettingsChange = () => {
}

logseq.provideStyle({
key: PL.id + '-threads',
key: PL.id,
style: providedStyles,
})
}
Expand All @@ -97,6 +98,13 @@ logseq
title: 'Thread colors',
type: 'string',
},
{
key: 'shouldColorThreads',
default: true,
description: 'Whether or not to color threads',
title: 'Color threads',
type: 'boolean',
},
{
key: 'shouldFillBars',
default: true,
Expand Down

0 comments on commit b2883ae

Please sign in to comment.