Skip to content

Commit

Permalink
Add filetree option
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Eskild Steensen committed Nov 3, 2022
1 parent 1e02f68 commit 1d6eca2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 50 deletions.
4 changes: 3 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ const DEFAULT_SETTINGS: DigitalGardenSettings = {
faviconPath: '',
showRibbonIcon: true,
noteSettingsIsInitialized: false,
siteName: 'Digital Garden',
defaultNoteSettings: {
dgHomeLink: true,
dgPassFrontmatter: false,
dgShowBacklinks: false,
dgShowLocalGraph: false,
dgShowInlineTitle: false
dgShowInlineTitle: false,
dgShowFileTree: false
}
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "digitalgarden",
"name": "Digital Garden",
"version": "2.21.0",
"version": "2.22.0",
"minAppVersion": "0.12.0",
"description": "Publish your notes to a digital garden for others to enjoy.",
"author": "Ole Eskild Steensen",
Expand Down
3 changes: 3 additions & 0 deletions src/DigitalGardenSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default interface DigitalGardenSettings {
baseTheme: string;
faviconPath: string;

siteName: string;

noteSettingsIsInitialized: boolean;

defaultNoteSettings: {
Expand All @@ -18,5 +20,6 @@ export default interface DigitalGardenSettings {
dgShowBacklinks: boolean;
dgShowLocalGraph: boolean;
dgShowInlineTitle: boolean;
dgShowFileTree: boolean;
}
}
11 changes: 9 additions & 2 deletions src/DigitalGardenSiteManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export default class DigitalGardenSiteManager implements IDigitalGardenSiteManag
const octokit = new Octokit({ auth: this.settings.githubToken });
const theme = JSON.parse(this.settings.theme);
const baseTheme = this.settings.baseTheme;
const siteName = this.settings.siteName;

let envSettings = '';
if (theme.name !== 'default') {
envSettings = `THEME=${theme.cssUrl}\nBASE_THEME=${baseTheme}`
envSettings = `THEME=${theme.cssUrl}\nBASE_THEME=${baseTheme}`;
}
envSettings+=`\nSITE_NAME_HEADER=${siteName}`;

const defaultNoteSettings = {...this.settings.defaultNoteSettings};
for(const key of Object.keys(defaultNoteSettings)) {
Expand Down Expand Up @@ -198,9 +200,14 @@ export default class DigitalGardenSiteManager implements IDigitalGardenSiteManag
"src/site/_includes/components/pageheader.njk",
"src/site/_includes/components/sidebar.njk",
"src/site/_includes/components/graphScript.njk",
"src/site/_includes/components/filetree.njk",
"src/site/_includes/components/filetreeNavbar.njk",
"src/site/_includes/components/navbar.njk",
"src/site/_data/versionednotes.js",
"src/site/_data/meta.js",
"src/site/img/outgoing.svg"
"src/site/_data/filetree.js",
"src/site/img/outgoing.svg",
"src/helpers/constants.js",
];

for (const file of filesToModify) {
Expand Down
72 changes: 26 additions & 46 deletions src/SettingView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ export default class SettingView {
this.saveNoteSettingsAndUpdateEnv();
})
})
new Setting(noteSettingsModal.contentEl)
.setName("Show filetree sidebar (dg-show-file-tree)")
.setDesc("When turned on, a filetree will be shown on your site.")
.addToggle(t => {
t.setValue(this.settings.defaultNoteSettings.dgShowFileTree)
t.onChange((val) => {
this.settings.defaultNoteSettings.dgShowFileTree = val;
this.saveNoteSettingsAndUpdateEnv();
})
})
}


Expand All @@ -118,7 +128,7 @@ export default class SettingView {

new Setting(this.settingsRootElement)
.setName("Appearance")
.setDesc("Manage themes and favicons on your site")
.setDesc("Manage themes, sitename and favicons on your site")
.addButton(cb => {
cb.setButtonText("Manage");
cb.onClick(async () => {
Expand Down Expand Up @@ -156,6 +166,17 @@ export default class SettingView {
});
});

new Setting(themeModal.contentEl)
.setName('Sitename')
.setDesc('The name of your site. This will be displayed as the site header.')
.addText(text =>
text.setValue(this.settings.siteName)
.onChange(async (value) => {
this.settings.siteName = value;
await this.saveSettings();
})
);

new Setting(themeModal.contentEl)
.setName("Favicon")
.setDesc("Path to an svg in your vault you wish to use as a favicon. Leave blank to use default.")
Expand Down Expand Up @@ -193,6 +214,7 @@ export default class SettingView {
await gardenManager.updateEnv();

new Notice("Successfully applied theme");
new Notice("Successfully set sitename");
}

private async saveNoteSettingsAndUpdateEnv() {
Expand All @@ -211,48 +233,6 @@ export default class SettingView {
}
}

private async updateEnv(octokit: Octokit) {
const theme = JSON.parse(this.settings.theme);
const baseTheme = this.settings.baseTheme;

let envSettings = '';
if (theme.name !== 'default') {
envSettings = `THEME=${theme.cssUrl}\nBASE_THEME=${baseTheme}`
}

const defaultNoteSettings = { ...this.settings.defaultNoteSettings };
for (const key of Object.keys(defaultNoteSettings)) {
//@ts-ignore
envSettings += `\n${key}=${defaultNoteSettings[key]}`;
}

const base64Settings = Base64.encode(envSettings);

let fileExists = true;
let currentFile = null;
try {
currentFile = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
owner: this.settings.githubUserName,
repo: this.settings.githubRepo,
path: ".env",
});
} catch (error) {
fileExists = false;
}

//commit
await octokit.request('PUT /repos/{owner}/{repo}/contents/{path}', {
owner: this.settings.githubUserName,
repo: this.settings.githubRepo,
path: ".env",
message: `Update settings`,
content: base64Settings,
sha: fileExists ? currentFile.data.sha : null
});


}

private async addFavicon(octokit: Octokit) {
let base64SettingsFaviconContent = "";
if (this.settings.faviconPath) {
Expand Down Expand Up @@ -299,7 +279,7 @@ export default class SettingView {
sha: faviconExists ? currentFaviconOnSite.data.sha : null
});

new Notice(`Successfully set new favicon`)
new Notice(`Successfully set favicon`)
}

}
Expand Down Expand Up @@ -382,7 +362,7 @@ export default class SettingView {
await this.saveSettings();
})
);
}
}

renderCreatePr(modal: Modal, handlePR: (button: ButtonComponent) => Promise<void>) {

Expand Down Expand Up @@ -443,7 +423,7 @@ export default class SettingView {
renderLoading() {
this.loading.show();
const text = "Creating PR. This should take less than 1 minute";
const loadingText = this.loading.createEl('h2', { text });
const loadingText = this.loading.createEl('h4', { text });
this.loadingInterval = setInterval(() => {
if (loadingText.innerText === `${text}`) {
loadingText.innerText = `${text}.`;
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"2.22.0": "0.12.0",
"2.21.0": "0.12.0",
"2.20.0": "0.12.0",
"2.19.0": "0.12.0",
Expand Down

0 comments on commit 1d6eca2

Please sign in to comment.