logseq-plugin-github-get
logseq-plugin-github-get copied to clipboard
Github File Getter (logseq-plugin-github-get)
Overview
This plugin allows the user to easily import the contents of files from any Github repository that the Github user has access to. The main goal is to enhance the ability to document code development and final code using Logseq.
Suggested Use
Create a new logseq graph in the root of your code repository under a /docs folder.
The logseq Journal can be used to document the day-by-day development progress.
As code is developed and pushed to Github, the code can be retrieved and inserted into a Logseq page block using this plugin.
The code can then be documented using Logseq's extensive note taking capabilities.
As a code file is updated and the changes pushed to Github, the code in Logseq can be immediately updated to the latest version using the refresh icon at the top of the code block.
Example
This example shows how to embed a file from a repository which is synced to Github. The repository is cloned locally and open in VS Code. The Github account name and repository name have been entered in the plugin settings as default, so only the relative path of the file needs to be entered.

One-Time Configuration
- Ensure you are running logseq version 0.6.5 or later.
- Open the logseq settings menu.
- Select
Plugin Settingsand click on theGithub File Gettertab. - Required: Enter a personal access token with full repository access rights in the field labeled
githubPat. For more information on how to generate a personal access token, look here. - Optional: Enter the default github account name that your repository resides in. Use your
username(not your email address) in the field labeledgithubAccount. If this is left empty you must provide the account for every repository file that you wish to retrieve. See the sectionRunning the Github Commandbelow for the correct URL to use. - Optional: Enter the name of the repository where your files reside. If this is left empty you must provide the account for every repository file that you wish to retrieve. See the section
Running the Github Commandbelow for the correct URL to use.
Using Logseq as a code documentation tool
- Open the local version of the repository that you want to document within your IDE (VS Code is used in the example given above).
- Create a root directory called
docs. - Open Logseq and select
Add a graphfrom the left sidebar graph menu item. - Navigate to the docs
folderthat you have just created. - Use Logseq to document your development process.
- When you are ready to document specific code in the repository, follow the
Running the Github Commandprocess described below.
Running the Github Command
Using with files in the default repository
- Ensure that the account name and the repository name are provided in the plugin settings. See the
One-Time Configurationsection above. - Ensure that the file is pushed to your Github repository. The plugin will retrieve the most recent version of the file. (A later version of this plugin will allow you to get a specific commit version of the file)
- Select the file within your IDE that you wish to embed within LogSeq.
- Copy the relative path of the file from the root of the local copy. (You can obtain this in VS Code by right-clicking on the file in the Explorer and selecting
Copy Relative Pathfrom the context menu). - Select an empty block in LogSeq where you want to import the file. Paste the relative path of the file. e.g.
src/package.json - Run the
Get Github Filecommand by entering/Get Github Fileafter the file path. - If the configuration and file path are correctly entered the code should appear immediately below the selected block.
Using with files in another Github repository and/or account
Step 4 should be amended as follows:
- If the file is not in the default repository, enter the name of repository, followed by a colon ':', before the relative path. e.g.
another-repo:src/package-json - If the file is not in the default account nor the default repository, enter the name of the account, followed by a double-colon '::', the name of the repository, followed by a colon ':', before the relative path.
another-account::yet-another-repo:src/package.json
The general URL format is <account name>::<repository name>:<relative filepath>
Refreshing the code
- Once a file has been retrieved frm Github the block's parent shows the filename, the commit id, and a
refreshicon. To retrieve the latest version of the code simply click on the filename or therefreshicon. NOTE This will overwrite the existing version of the code. - To guard against accidental refresh, click on the commit id. This will toggle a
pinicon. When the pin icon is visible the refresh button is disabled. - To re-enable refresh, click the commit id again. The pin icon will disappear.
Installing the Plugin Manually
- Clone the plugin repo to a local folder.
- In logseq, open
Logseq→Settings, enable developer mode. - Open
Logseq→Plugins, chooseLoad unpacked plugin, and select the location where you saved the source code. - Follow the configuration steps given above.
- The
Get Github Filecommand should now be installed and active.
Supported file types
The file types supported by Code Mirror will be recognized and the appropriate code parser selected for the code block.