├── .github ├── FUNDING.yml └── workflows │ ├── release.yml │ └── version.yml ├── .gitignore ├── .npmrc ├── LICENSE ├── README.md ├── main.ts ├── manifest.json ├── package.json ├── rollup.config.js └── tsconfig.json /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: deathau 2 | custom: ["https://www.paypal.me/deathau"] 3 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release Obsidian Plugin 2 | on: 3 | push: 4 | # Sequence of patterns matched against refs/tags 5 | tags: 6 | - '*' # Push events to matching any tag format, i.e. 1.0, 20.15.10 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | with: 13 | fetch-depth: 0 # otherwise, you will failed to push refs to dest repo 14 | - name: Use Node.js 15 | uses: actions/setup-node@v1 16 | with: 17 | node-version: '14.x' # You might need to adjust this value to your own version 18 | # Get the version number and put it in a variable 19 | # https://stackoverflow.com/a/58178121/304786 20 | - name: Get Version 21 | id: version 22 | run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} 23 | # Build the plugin 24 | - name: Build 25 | id: build 26 | run: | 27 | npm install 28 | npm run build --if-present 29 | # Package the required files into a zip 30 | - name: Package 31 | run: | 32 | mkdir ${{ github.event.repository.name }} 33 | cp main.js manifest.json README.md ${{ github.event.repository.name }} 34 | zip -r ${{ github.event.repository.name }}.zip ${{ github.event.repository.name }} 35 | # Create the release on github 36 | - name: Create Release 37 | id: create_release 38 | uses: actions/create-release@v1 39 | env: 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 | VERSION: ${{ github.ref }} 42 | with: 43 | tag_name: ${{ github.ref }} 44 | release_name: ${{ github.ref }} 45 | draft: false 46 | prerelease: false 47 | # Upload the packaged release file 48 | - name: Upload zip file 49 | id: upload-zip 50 | uses: actions/upload-release-asset@v1 51 | env: 52 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 53 | with: 54 | upload_url: ${{ steps.create_release.outputs.upload_url }} 55 | asset_path: ./${{ github.event.repository.name }}.zip 56 | asset_name: ${{ github.event.repository.name }}-${{ steps.version.outputs.tag }}.zip 57 | asset_content_type: application/zip 58 | # Upload the main.js 59 | - name: Upload main.js 60 | id: upload-main 61 | uses: actions/upload-release-asset@v1 62 | env: 63 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 64 | with: 65 | upload_url: ${{ steps.create_release.outputs.upload_url }} 66 | asset_path: ./main.js 67 | asset_name: main.js 68 | asset_content_type: text/javascript 69 | # Upload the manifest.json 70 | - name: Upload manifest.json 71 | id: upload-manifest 72 | uses: actions/upload-release-asset@v1 73 | env: 74 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 75 | with: 76 | upload_url: ${{ steps.create_release.outputs.upload_url }} 77 | asset_path: ./manifest.json 78 | asset_name: manifest.json 79 | asset_content_type: application/json -------------------------------------------------------------------------------- /.github/workflows/version.yml: -------------------------------------------------------------------------------- 1 | name: Bump Version 2 | on: 3 | workflow_dispatch: 4 | inputs: 5 | type: 6 | description: 'Type of version (`major`, `minor`, `patch`)' 7 | required: true 8 | default: 'patch' 9 | jobs: 10 | bump: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | with: 15 | persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token 16 | fetch-depth: 0 # otherwise, you will failed to push refs to dest repo 17 | token: ${{secrets.PAT}} # use a personal acces token so that other actions can trigger 18 | # Bump the version number 19 | - name: Update Version 20 | uses: MCKanpolat/auto-semver-action@1.0.5 21 | id: version 22 | with: 23 | releaseType: ${{ github.event.inputs.type }} 24 | github_token: ${{ secrets.PAT }} 25 | # update the manifest.json with the new version 26 | - name: Update manifest version 27 | uses: jossef/action-set-json-field@v1 28 | with: 29 | file: manifest.json 30 | field: version 31 | value: ${{ steps.version.outputs.version }} 32 | # Commit the manifest.json and update the tag 33 | - name: Commit manifest 34 | run: | 35 | git config --local user.name "GitHub Action" 36 | git config --local user.email "action@github.com" 37 | git branch --show-current 38 | git add -u 39 | git commit -m "${{ steps.version.outputs.version }}" 40 | git tag -fa ${{ steps.version.outputs.version }} -m "${{ steps.version.outputs.version }}" 41 | # push the commit 42 | - name: Push changes 43 | uses: ad-m/github-push-action@v0.6.0 44 | with: 45 | github_token: ${{secrets.PAT}} 46 | tags: true 47 | branch: ${{ github.ref }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Intellij 2 | *.iml 3 | .idea 4 | 5 | # npm 6 | node_modules 7 | package-lock.json 8 | 9 | # build 10 | main.js 11 | styles.css 12 | *.js.map 13 | data.json 14 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | tag-version-prefix = "" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 deathau 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Snippet Commands Obsidian Plugin 2 | [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/deathau/snippet-commands-obsidian?style=for-the-badge&sort=semver)](https://github.com/deathau/snippet-commands-obsidian/releases/latest) 3 | ![GitHub All Releases](https://img.shields.io/github/downloads/deathau/snippet-commands-obsidian/total?style=for-the-badge) 4 | 5 | A plugin for [Obsidian](https://obsidian.md) to add all your CSS snippets as commands, accessible from the command pallette and even assignable to hotkeys! 6 | 7 | **Important:** If your snippets change while Obsidian is running, there is also a command to "Reload all snippet commands" 8 | 9 | ### Compatibility 10 | 11 | Compatible with Obsidian v0.9.18+ (when the CSS snippets were introduced). 12 | 13 | ### Notes 14 | This is all very experimental at the moment, so parts might not work, etc. 15 | 16 | ## Installation 17 | 18 | ### From within Obsidian 19 | From Obsidian v0.9.8, you can activate this plugin within Obsidian by doing the following: 20 | - Open Settings > Third-party plugin 21 | - Make sure Safe mode is **off** 22 | - Click Browse community plugins 23 | - Search for this plugin 24 | - Click Install 25 | - Once installed, close the community plugins window and activate the newly installed plugin 26 | #### Updates 27 | You can follow the same procedure to update the plugin 28 | 29 | ### From GitHub 30 | - Download the Latest Release from the Releases section of the GitHub Repository 31 | - Extract the plugin folder from the zip to your vault's plugins folder: `/.obsidian/plugins/` 32 | Note: On some machines the `.obsidian` folder may be hidden. On MacOS you should be able to press `Command+Shift+Dot` to show the folder in Finder. 33 | - Reload Obsidian 34 | - If prompted about Safe Mode, you can disable safe mode and enable the plugin. 35 | Otherwise head to Settings, third-party plugins, make sure safe mode is off and 36 | enable the plugin from there. 37 | 38 | ## Security 39 | > Third-party plugins can access files on your computer, connect to the internet, and even install additional programs. 40 | 41 | The source code of this plugin is available on GitHub for you to audit yourself, but installing plugins into Obsidian is currently a matter of trust. 42 | 43 | I can assure you here that I do nothing to collect your data, send information to the internet or otherwise do anything nefarious with your system. However, be aware that I *could*, and you only have my word that I don't. 44 | 45 | ## Development 46 | 47 | This project uses Typescript to provide type checking and documentation. 48 | The repo depends on the latest [plugin API](https://github.com/obsidianmd/obsidian-api) in Typescript Definition format, which contains TSDoc comments describing what it does. 49 | 50 | If you want to contribute to development and/or just customize it with your own 51 | tweaks, you can do the following: 52 | - Clone this repo. 53 | - `npm i` or `yarn` to install dependencies 54 | - `npm run build` to compile. 55 | - Copy `manifest.json`, `main.js` and `styles.css` to a subfolder of your plugins 56 | folder (e.g, `/.obsidian/plugins//`) 57 | - Reload obsidian to see changes 58 | 59 | Alternately, you can clone the repo directly into your plugins folder and once 60 | dependencies are installed use `npm run dev` to start compilation in watch mode. 61 | You may have to reload obsidian (`ctrl+R`) to see changes. 62 | 63 | ## Pricing 64 | Huh? This is an open-source plugin I made *for fun*. It's completely free. 65 | However, if you absolutely *have* to send me money because you like it that 66 | much, feel free to throw some coins in my hat via the following: 67 | 68 | [![GitHub Sponsors](https://img.shields.io/github/sponsors/deathau?style=social)](https://github.com/sponsors/deathau) 69 | [![Paypal](https://img.shields.io/badge/paypal-deathau-yellow?style=social&logo=paypal)](https://paypal.me/deathau) 70 | 71 | # Version History 72 | 73 | ## 0.0.1 74 | Initial Release 75 | -------------------------------------------------------------------------------- /main.ts: -------------------------------------------------------------------------------- 1 | import { Plugin } from 'obsidian'; 2 | 3 | export default class SnippetCommandsPlugin extends Plugin { 4 | 5 | onload() { 6 | this.enableCommands(); 7 | } 8 | 9 | onunload() { 10 | } 11 | 12 | reloadCommands() { 13 | this.unload() 14 | this.load(); 15 | } 16 | 17 | enableCommands() { 18 | const customCss = (this.app as any).customCss; 19 | const knownSnippets = customCss.snippets; 20 | console.log(`[Snippet Commands]: Loading commands for ${knownSnippets.length} snippets`, knownSnippets); 21 | knownSnippets.forEach((snippet:string) => { 22 | this.addCommand({ 23 | id: `snippet-command-${snippet}`, 24 | name: `Toggle ${snippet}`, 25 | callback: () => { 26 | customCss.setCssEnabledStatus(snippet, !customCss.enabledSnippets.has(snippet)); 27 | } 28 | }); 29 | }); 30 | this.addCommand({ 31 | id: `snippet-command-reload-all-snippets`, 32 | name: `Reload snippet commands`, 33 | callback: () => { 34 | this.reloadCommands(); 35 | } 36 | }); 37 | } 38 | } -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "snippet-commands-obsidian", 3 | "name": "Snippet Commands", 4 | "version": "0.0.2", 5 | "minAppVersion": "0.9.18", 6 | "description": "Registers custom css snippets as commands (which you can bind hotkeys to)", 7 | "author": "death_au", 8 | "authorUrl": "https://github.com/deathau", 9 | "isDesktopOnly": false 10 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "snippet-commands-obsidian", 3 | "version": "0.0.0", 4 | "description": "Registers custom css snippets as commands (which you can bind hotkeys to)", 5 | "main": "main.js", 6 | "scripts": { 7 | "instal-deps": "npm install", 8 | "dev": "rollup --config rollup.config.js -w", 9 | "build": "rollup --config rollup.config.js --environment BUILD:production" 10 | }, 11 | "keywords": [], 12 | "author": "death_au", 13 | "license": "MIT", 14 | "devDependencies": { 15 | "@rollup/plugin-commonjs": "^18.0.0", 16 | "@rollup/plugin-node-resolve": "^11.2.1", 17 | "@rollup/plugin-typescript": "^8.2.1", 18 | "@types/node": "^14.14.37", 19 | "obsidian": "^0.12.0", 20 | "rollup": "^2.32.1", 21 | "tslib": "^2.2.0", 22 | "typescript": "^4.2.4" 23 | }, 24 | "dependencies": {} 25 | } 26 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import typescript from '@rollup/plugin-typescript'; 2 | import {nodeResolve} from '@rollup/plugin-node-resolve'; 3 | import commonjs from '@rollup/plugin-commonjs'; 4 | 5 | const isProd = (process.env.BUILD === 'production'); 6 | 7 | const banner = 8 | `/* 9 | THIS IS A GENERATED/BUNDLED FILE BY ROLLUP 10 | if you want to view the source visit the plugins github repository 11 | */ 12 | `; 13 | 14 | export default { 15 | input: 'main.ts', 16 | output: { 17 | dir: '.', 18 | sourcemap: 'inline', 19 | sourcemapExcludeSources: isProd, 20 | format: 'cjs', 21 | exports: 'default', 22 | banner, 23 | }, 24 | external: ['obsidian'], 25 | plugins: [ 26 | typescript(), 27 | nodeResolve({browser: true}), 28 | commonjs(), 29 | ] 30 | }; -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "inlineSourceMap": true, 5 | "inlineSources": true, 6 | "module": "ESNext", 7 | "target": "es6", 8 | "allowJs": true, 9 | "noImplicitAny": true, 10 | "moduleResolution": "node", 11 | "importHelpers": true, 12 | "lib": [ 13 | "dom", 14 | "es5", 15 | "scripthost", 16 | "es2015" 17 | ] 18 | }, 19 | "include": [ 20 | "**/*.ts" 21 | ] 22 | } --------------------------------------------------------------------------------