Skip to content

Commit

Permalink
Merge pull request #32 from Nodsoft/develop
Browse files Browse the repository at this point in the history
Add Astro presentation website
  • Loading branch information
SakuraIsayeki authored Feb 16, 2024
2 parents 2e8c5ba + 1b6a245 commit 6a2b2c7
Show file tree
Hide file tree
Showing 61 changed files with 71,851 additions and 24 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ permissions:


on:
- push
- pull_request
- workflow_call
push:
paths-ignore:
- 'nodsoft_moltenobsidian_web/**'
- 'nodsoft_moltenobsidian_ssg_client/**'
pull_request:
workflow_call:

jobs:
build:
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/deploy-astro-website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Deploy Astro website to GitHub Pages

on:
# Trigger the workflow every time you push to the `main` branch
# Using a different branch name? Replace `main` with your branch’s name
push:
branches: [ main, feature/web ]
paths:
- 'nodsoft_moltenobsidian_web/**'
- 'nodsoft_moltenobsidian_ssg_client/**'
- '.github/workflows/deploy-astro-website.yml'
# Allows you to run this workflow manually from the Actions tab on GitHub.
workflow_dispatch:

# Allow this job to clone the repo and create a page deployment
permissions:
contents: read
pages: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup MoltenObsidian
uses: nodsoft/setup-moltenobsidian@main

- name: Generate Vault manifest
run: moltenobsidian manifest generate "nodsoft_moltenobsidian_web/vault"

- name: Create output directory (recursive)
run: mkdir -p "nodsoft_moltenobsidian_web/public/vault"

- name: Generate SSG assets
run: |
moltenobsidian ssg generate \
--from-folder "nodsoft_moltenobsidian_web/vault" \
--output-path "nodsoft_moltenobsidian_web/public/vault" \
--ignored-files ".gitignore"
- name: Install PNPM
run: npm install -g pnpm

- name: Install dependencies
run: |
cd "nodsoft_moltenobsidian_ssg_client"
pnpm recursive install --prod
- name: Install, build, and upload
uses: withastro/action@v1
with:
path: nodsoft_moltenobsidian_web # The root location of your Astro project inside the repository. (optional)
# node-version: 18 # The specific version of Node that should be used to build your site. Defaults to 18. (optional)
package-manager: pnpm@latest # The Node package manager that should be used to install dependencies and build your site. Automatically detected based on your lockfile. (optional)

deploy:
needs: build
runs-on: ubuntu-latest

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v3
4 changes: 4 additions & 0 deletions .github/workflows/nuget-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
- main
# - develop
- v*
paths-ignore:
- 'nodsoft_moltenobsidian_web/**'
- 'nodsoft_moltenobsidian_ssg_client/**'
- 'Samples/**'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
17 changes: 17 additions & 0 deletions .run/Generate docs manifest.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Generate docs manifest" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="moltenobsidian manifest generate &quot;./vault&quot; --output &quot;./src/assets/vault&quot; --ignore-file &quot;.gitignore&quot; --force --debug" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="false" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/nodsoft_moltenobsidian_web" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>
17 changes: 17 additions & 0 deletions .run/Generate site content.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Generate site content" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="moltenobsidian ssg generate --from-folder &quot;./vault&quot; --output-path &quot;./src/assets/vault&quot; --ignored-files &quot;.gitignore&quot; --debug" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="false" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/nodsoft_moltenobsidian_web" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>
4 changes: 2 additions & 2 deletions Nodsoft.MoltenObsidian.Manifest/VaultManifestGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static async Task<RemoteVaultManifest> GenerateManifestAsync(IVault vault
{
if (file.Name is not RemoteVaultManifest.ManifestFileName)
{
files.Add(await ExtractManifestAsync(file));
files.Add(await ExtractManifestInfoAsync(file));
}
}

Expand All @@ -39,7 +39,7 @@ public static async Task<RemoteVaultManifest> GenerateManifestAsync(IVault vault
/// </summary>
/// <param name="file">The file to extract information from.</param>
/// <returns>A <see cref="ManifestFile"/> instance.</returns>
private static async Task<ManifestFile> ExtractManifestAsync(IVaultFile file)
private static async Task<ManifestFile> ExtractManifestInfoAsync(IVaultFile file)
{
// Read the file. We'll need it later.
await using Stream stream = await file.OpenReadAsync();
Expand Down
10 changes: 6 additions & 4 deletions Nodsoft.MoltenObsidian/Converter/ObsidianHtmlConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ public ObsidianHtmlConverter(MarkdownPipeline pipeline)
/// <param name="markdown">The Markdown to convert.</param>
/// <returns>The converted Markdown, in HTML format.</returns>
// ReSharper disable once RedundantNameQualifier
public string Convert(string markdown) => Markdig.Markdown.ToHtml(markdown, _pipeline);
public string Convert(string markdown) => Markdown.ToHtml(markdown, _pipeline);

/// <inheritdoc cref="Convert(string)" />
/// <summary>
/// Converts Obsidian-flavoured Markdown to HTML.
/// </summary>
/// <param name="markdown">The Markdown to convert.</param>
/// <param name="currentFile">The current file whose contents are being converted.</param>
// ReSharper disable once RedundantNameQualifier
public string Convert(string markdown, IVaultNote currentFile)
=> Markdig.Markdown.ToHtml(markdown, _pipeline, new()
=> Markdown.ToHtml(markdown, _pipeline, new()
{
Properties =
{
Expand Down
15 changes: 2 additions & 13 deletions Nodsoft.MoltenObsidian/Converter/ObsidianPipelineBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
using ColorCode.Styling;
using Markdig;
using Nodsoft.Markdig.SyntaxHighlighting;
using Nodsoft.MoltenObsidian.Infrastructure.Markdown;

#if NET6_0_OR_GREATER
using Markdown.ColorCode;
#else
using Markdig.SyntaxHighlighting;
#endif


namespace Nodsoft.MoltenObsidian.Converter;

/// <summary>
Expand All @@ -24,12 +18,7 @@ public ObsidianPipelineBuilder(bool useBootstrap = false, bool darkTheme = false
// Configure the pipeline for all features. This should enable 90% of all Obsidian MD features.
this.UseAdvancedExtensions()
.UseInternalLinks()
#if NET6_0_OR_GREATER
.UseColorCode(darkTheme ? StyleDictionary.DefaultDark : StyleDictionary.DefaultLight)
#else
.UseSyntaxHighlighting()
#endif
;
.UseSyntaxHighlighting(darkTheme ? StyleDictionary.DefaultDark : StyleDictionary.DefaultLight);

// Configure the pipeline for Bootstrap support, if requested.
if (useBootstrap)
Expand Down
4 changes: 2 additions & 2 deletions Nodsoft.MoltenObsidian/Nodsoft.MoltenObsidian.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="Markdig" Version="0.31.0" />
<PackageReference Include="Markdig" Version="0.32.0" />
<PackageReference Include="Nodsoft.Markdig.SyntaxHighlighting" Version="1.0.8" />
<PackageReference Include="YamlDotNet" Version="13.1.0" />
<PackageReference Include="Markdown.ColorCode" Version="1.0.4" />
</ItemGroup>

</Project>
90 changes: 90 additions & 0 deletions nodsoft_moltenobsidian_ssg_client/manifest-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import {VaultFile, VaultManifest} from 'vault-manifest'
import YAML from 'yaml'

/**
* Represents a client for resolving a MoltenObsidian vault's assets from its manifest.
* @class
* @public
*/
export class VaultManifestClient {
protected _routingTable: Map<string, VaultFile> | undefined;

public static fromManifest(manifest: VaultManifest) {
return new VaultManifestClient(manifest);
}

public static async fromPath(path: string | URL) {
// Fetch the manifest from the URL
const response = await fetch(path);
if (!response.ok) {
throw new Error(`Failed to fetch manifest from ${path.toString()}: ${response.statusText}`);
}

const manifest = await response.json() as VaultManifest;
return VaultManifestClient.fromManifest(manifest);
}

protected constructor(
public readonly Manifest: VaultManifest
) { }

public get routingTable() {
if (!this._routingTable) {
this._routingTable = this.buildRoutingTable();
}

return this._routingTable;
}

private buildRoutingTable() {
const routingTable = new Map<string, VaultFile>();

for (const file of this.Manifest.files) {
// If markdown, add to routing table
if (!file.path.endsWith('.md')) {
continue;
}

// Exclusion cases
if ((file.moltenobsidian?.publish ?? file.publish) == false) {
continue;
}

const indexFileRegex = /(\/?index\.md|readme\.md)$/ig;
if (file.path.match(indexFileRegex)) {
console.log(file.path, file.path.replace(indexFileRegex, ''));
routingTable.set(file.path.replace(indexFileRegex, ''), file);
}
else if (file.path.endsWith('.md')) {
const mdRegex = /\.md$/;
routingTable.set(file.path.replace(mdRegex, ''), file);
// routingTable.set(file.path.replace(mdRegex, '.html'), file);
}

// routingTable.set(file.path, file);
}

return routingTable;
}

getSsgPath(file: { path: string }) {
let path = file.path;
if (path.startsWith('/')) {
path = path.substring(1);
}

return path.replace(/\.md$/, '.html');
}

public static getFrontMatter(file: string | BinaryData) {
if (typeof file !== 'string') {
file = new TextDecoder().decode(file);
}

return YAML.parse(file);
}

public getFrontMatterFilePath(path: string) {
return path.replace(/\.md$|\.html$/, '.yaml');
}
}
16 changes: 16 additions & 0 deletions nodsoft_moltenobsidian_ssg_client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "moltenobsidian-ssg-client",
"author": "Nodsoft Systems",
"description": "SSG Client for MoltenObsidian vaults",
"license": "ISC",
"scripts": {
"build": "tsc"
},
"devDependencies": {
"typescript": "^5.1.6"
},
"dependencies": {
"@types/mime-types": "^2.1.1",
"yaml": "^2.3.1"
}
}
35 changes: 35 additions & 0 deletions nodsoft_moltenobsidian_ssg_client/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6a2b2c7

Please sign in to comment.