|
| 1 | +--- |
| 2 | +title: Open Azure DevOps Wikis in Obsidian |
| 3 | +date: 2024-07-25T16:46:28 |
| 4 | +draft: true |
| 5 | +tags: |
| 6 | + - Obsidian |
| 7 | + - AzureDevOps |
| 8 | +--- |
| 9 | + |
| 10 | +- Make sure you have [Git 2.25.0](https://git-scm.com/downloads) or greater. |
| 11 | +- Clone the repository that holds the wiki pages |
| 12 | + - If the wiki was created as a project wiki (not by publishing code as a wiki) and it is not listed in the repository view, you can still clone it by using its "secret path": `git clone https://dev.azure.com/<organization>/<project>/_git/<name of wiki>.wiki` |
| 13 | +- Make sure the stage is clean and all changes have been commited |
| 14 | +- The following instructions keep all "customizations" local to each committer, so the wiki does not require the use of Obsidian. |
| 15 | +- This means that the following steps need to be performed by everyone who wants to use Obsidian to work with the wiki files. |
| 16 | + |
| 17 | +## Make sure to use a global attachments folder |
| 18 | + |
| 19 | +- Azure DevOps allows to use a global folder for attachments and pictures, called `/.attachments`. This allows to link to attachments without using absolute or relative paths: |
| 20 | + - For example `` will be a valid path to `img1.png`, regardless where the page that contains that file is located within the repository. |
| 21 | +- The same thing is possible in Obsidian with the limitation that the global attachment folder **cannot** start with a dot. At the same time, in Azure DevOps, it has to start with a dot, which creates a problem that we have to work around. |
| 22 | + |
| 23 | +- We can work around this problem by creating a separate attachment folder for Obsidian and making sure that all images are included from there when checked out locally, and from the appropriate `.attachments` folder when the wiki is opened in Azure DevOps. |
| 24 | + - Unfortunately symlinks or directory junctions are also not supported by obsidian... |
| 25 | +- This requires to change the linking of attachments and pictures in the markdown files when checking them out locally, which can be done by using [git clean/smudge filters](https://medium.com/@dimst23/a-hidden-gem-of-git-clean-smudge-filter-6c27bee20081). |
| 26 | +- using a global attachments folder in Obsidian that is called `_attachments` and a git smudge filter that makes sure, Azure DevOps only sees its `.attachment` |
| 27 | + |
| 28 | +- Change to the root of your local reposity and delete the working directory: |
| 29 | + |
| 30 | +```bash |
| 31 | +rm .git/index |
| 32 | +git clean -df |
| 33 | +``` |
| 34 | + |
| 35 | +- If your repo already has an `.gitignore` file check it out. If it doesn't, create one and make sure it ignores the folders `_attachments`, `.obsidian` and all of their contents. |
| 36 | + |
| 37 | +```bash |
| 38 | +git checkout HEAD .gitignore # If repo has a .gitignore |
| 39 | +echo "_attachments/" >> .gitignore |
| 40 | +echo ".obsidian/" >> .gitignore |
| 41 | +``` |
| 42 | + |
| 43 | +- If your repo already has an `.gitattributes` file check it out. If it doesn't, create one and add a rule that applies a text filter called "attachmentsFolder" to all markdown files. |
| 44 | + |
| 45 | +```bash |
| 46 | +git checkout HEAD .gitattributes # If repo has a .gitignore |
| 47 | +echo "*.md text filter=attachmentsFolder" >> .gitattributes |
| 48 | +``` |
| 49 | + |
| 50 | +- Now add the respective filter to your repo local git configuration: |
| 51 | + |
| 52 | +```powershell |
| 53 | +git config filter.attachmentsFolder.smudge "sed -e 's/\.attachments/_attachments/g'" |
| 54 | +git config filter.attachmentsFolder.clean "sed -e 's/_attachments/.attachments/g'" |
| 55 | +``` |
| 56 | + |
| 57 | +- Next we create git hooks that trigger a sync of the content of the two attachment folders. |
| 58 | +- For the sync we use [robocopy](https://learn.microsoft.com/de-de/windows-server/administration/windows-commands/robocopy) which is a built in tool in Windows 11. |
| 59 | + |
| 60 | +- Add the following to `.git/hooks/pre-commit` (create if it does not exist) to copy new attachments from `_attachments` (Obsidian) to `.attachments` (Repo) when creating a new commit. |
| 61 | + |
| 62 | +```bash |
| 63 | +#!/bin/sh |
| 64 | + |
| 65 | +echo "[pre-commit hook] Updating repo with local attachments" |
| 66 | +pwsh -noprofile -c 'iex "robocopy _attachments .attachments /mir /njh /njs /ndl"' |
| 67 | +git add .attachments |
| 68 | +``` |
| 69 | + |
| 70 | +- The following code copies attachments from `.attachments` (Repo) to `_attachments` (Obsidian): |
| 71 | + |
| 72 | +```shell |
| 73 | +#!/bin/sh |
| 74 | + |
| 75 | +echo "[post-checkout hook] Updating local attachments with updates from repo" |
| 76 | +pwsh -noprofile -c 'iex "robocopy .attachments _attachments /mir /njh /njs /ndl"' |
| 77 | +``` |
| 78 | + |
| 79 | +- In order to work reliably it needs to be added to the following files (create if they do not exist): |
| 80 | + - `.git/hooks/post-checkout` (applied after git pull and change of branches) |
| 81 | + - `.git/hooks/post-rewrite` (applied after rebase) |
| 82 | + - `.git/hooks/post-merge` (applied after merge) |
| 83 | + |
| 84 | +- Check out the working directory to apply the smudge filter to all Markdown files (may take some time): |
| 85 | + |
| 86 | +```bash |
| 87 | +git checkout HEAD . |
| 88 | +``` |
| 89 | + |
| 90 | +## Open the repository in Obsidian as vault |
| 91 | + |
| 92 | +- Open vault from folder |
| 93 | +- Disable unnecessart plugins |
| 94 | + |
| 95 | +- Change attachment folder path to `_attachments` |
| 96 | +- Disable wiki links |
| 97 | +- Set the format for new links to "relative" |
| 98 | + |
| 99 | +## Recommended plugins |
| 100 | + |
| 101 | +### Plugin Folder Note |
| 102 | + |
| 103 | +- Creates a note that automatically serves as the index of a folder. |
| 104 | +- This is supported by Azure DevOps. |
| 105 | +- Folder Node Plugin Settings: |
| 106 | + - Set the "Note File Method" to "Folder Name Outside" |
| 107 | + - If the code `[[_ TOSP _]]` is added to the "Initial Content" of such a folder file it will be shown as a dynamic table of contents of the respective folder in Azure DevOps ([TOSP: Table of Sub Pages](https://learn.microsoft.com/en-us/azure/devops/project/wiki/markdown-guidance?view=azure-devops#add-a-subpages-table)). |
| 108 | + - Set the "Hide Folder Node" and "Auto Rename" option. |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +### Other plugins |
| 114 | + |
| 115 | +- Quickadd |
| 116 | +- Obisidian git (untested) |
0 commit comments