Skip to content

Commit

Permalink
inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Gremler committed Jun 13, 2023
0 parents commit 24b7d3d
Show file tree
Hide file tree
Showing 11 changed files with 1,937 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
63 changes: 63 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build plugin

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- '*' # Push events to matching any tag format, i.e. 1.0, 20.15.10

env:
PLUGIN_NAME: logseq-footnote-plugin

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '16.x' # You might need to adjust this value to your own version
- name: Build
id: build
run: |
npm i && npm run build
mkdir ${{ env.PLUGIN_NAME }}
cp readme.md package.json icon.png ${{ env.PLUGIN_NAME }}
mv dist ${{ env.PLUGIN_NAME }}
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
ls
echo "::set-output name=tag_name::$(git tag --sort version:refname | tail -n 1)"
- 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 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 }}-${{ steps.build.outputs.tag_name }}.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
119 changes: 119 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
.DS_Store
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test
.env.production

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Timo Gremler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file added demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>logseq-custom-workflows</title>
</head>
<body>
<div id="app"></div>
<script src="index.js" type="module"></script>
</body>
</html>
94 changes: 94 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import '@logseq/libs';
//TODO Problem das sich der Text löscht wenn zu schnell befehl geschrieben wird
async function addFootnote (e) {

//Need Vars
var footnotesNumbers =0;
var footnotearray = []
var footnoteindex=0;
var regexFootNoteIndex=/\[\^(\d+)\]/g
var header = false;
var headerUUID=""

var normalPage = await getPageObject()
let currentpageBlockTree = await logseq.Editor.getPageBlocksTree(normalPage.uuid)
for (let i = 0; i < currentpageBlockTree.length; i++) {
//check if header exists
if(currentpageBlockTree[i].content == `## Footnotes`){
header=true
headerUUID = currentpageBlockTree[i].uuid
}

//Get index of footnote
if(currentpageBlockTree[i].content.match(regexFootNoteIndex)){
var str = currentpageBlockTree[i].content
footnotesNumbers = getFirstRegexGroup(regexFootNoteIndex,str)
footnotearray.push(parseInt(footnotesNumbers[0]))
}
// loop thourgh first children
// Due to the indexes under the Footnoteheader we dont need to go deeper, because it will use the number under the footnote header
if (currentpageBlockTree[i].children.length > 0) {
for (let j = 0; j < currentpageBlockTree[i].children.length; j++) {
if(currentpageBlockTree[i].children[j].content.match(regexFootNoteIndex)){
var str = currentpageBlockTree[i].children[j].content
footnotesNumbers = getFirstRegexGroup(regexFootNoteIndex, str)
footnotearray.push(parseInt(footnotesNumbers[0]))
}
}
}
}

if(footnotearray === undefined || footnotearray.length == 0 ){
footnoteindex += 1
}else{
footnoteindex = Math.max.apply(Math, footnotearray) + 1
}

if(header == false){
var normalPage = await getPageObject()
await logseq.Editor.appendBlockInPage(normalPage.uuid, `## Footnotes`)
//Because we need the Footnote header UUID in order to append the sources index we need to load again the PageBlocksTree
let currentpageBlockTree = await logseq.Editor.getPageBlocksTree(normalPage.uuid)
for (let i = 0; i < currentpageBlockTree.length; i++) {
if(currentpageBlockTree[i].content == `## Footnotes`){
header=true
headerUUID = currentpageBlockTree[i].uuid
}
}
}

//adding footnote to text
const block = await logseq.Editor.getBlock(e.uuid)
const newBlockText = block.content + "[^"+ footnoteindex +"]"
logseq.Editor.updateBlock(e.uuid, newBlockText)

//jup to footnotes header in order to place source
const footNoteSourceText = "[^"+footnoteindex+"]: "
await logseq.Editor.insertBlock(headerUUID, footNoteSourceText, {sibling: false})

}

function getFirstRegexGroup(regexp, str) {
return Array.from(str.matchAll(regexp), m => m[1]);
}

async function getPageObject(){
//Due to different pages/blocks (Journal/Subblocks/normal pages) we need different ways to get the id of the current page
var normalPage = await logseq.Editor.getCurrentPage()
if(normalPage != null && normalPage.hasOwnProperty("page")){
normalPage = await logseq.Editor.getPage(normalPage.page.id)
}else if(normalPage == null){
var normalPage = await logseq.Editor.getCurrentBlock()
normalPage = await logseq.Editor.getPage(normalPage.page.id)
}
return normalPage
}

async function main() {
console.log('plugin loaded');
logseq.Editor.registerSlashCommand('Add Footnote', async (e) => {
addFootnote(e)
})
}

logseq.ready(main).catch(console.error);
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "logseq-footnote-plugin",
"version": "0.0.1",
"description": "Easy Footnote Plugin",
"main": "dist/index.html",
"targets": {
"main": false
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "parcel build --no-source-maps index.html --public-url ./"
},
"keywords": [],
"author": "Timo Gremler",
"license": "MIT",
"dependencies": {
"@logseq/libs": "0.0.15"
},
"logseq": {
"id": "logseq-footnote-plugin",
"title": "Easy and Simple Footnotes",
"icon": "./icon.png"
},
"devDependencies": {
"parcel": "^2.0.0"
}
}
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Easy and Simple Footnotes
A easy and simple plugin to create footnotes. It will create footnotes on the current cursor location and an additional footnote heading.
In order to call the plugin use the Slash Command `/Add Footnote`.

# How to use

![](./demo.gif)

Loading

0 comments on commit 24b7d3d

Please sign in to comment.