Compare commits
2 Commits
e9b1a95b9a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 17dd144124 | |||
| 5b3709cecf |
3
.env
3
.env
@@ -1,5 +1,4 @@
|
|||||||
obsidian_vault=/home/venus/Documents/Personal-Wiki
|
obsidian_vault=/home/venus/Documents/Personal-Wiki
|
||||||
obsidian_vault_url=git.riverrooks.dev/Personal-Wiki
|
obsidian_vault_url=https://git.riverrooks.dev/Personal-Wiki
|
||||||
OBSIDIAN_VAULT_URL=git.riverrooks.dev/Personal-Wiki
|
|
||||||
obsidian_vault_token=bd8cd9301ae2c1c5bacfb3340492acb5e862686a
|
obsidian_vault_token=bd8cd9301ae2c1c5bacfb3340492acb5e862686a
|
||||||
|
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1 @@
|
|||||||
app/__pychache__
|
app/__pychache__
|
||||||
public-vault
|
|
||||||
|
|||||||
21
Dockerfile
21
Dockerfile
@@ -1,25 +1,12 @@
|
|||||||
FROM python:3.14-slim
|
FROM python:3.14-slim
|
||||||
|
|
||||||
#install git
|
|
||||||
RUN apt-get update && apt-get install -y \
|
|
||||||
git \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
#install dependencies
|
|
||||||
RUN mkdir /app
|
|
||||||
COPY app/requirements.txt /app
|
|
||||||
RUN pip3 install -r /app/requirements.txt
|
|
||||||
|
|
||||||
#parse from .env file
|
|
||||||
ARG DEBUG_MODE=0
|
ARG DEBUG_MODE=0
|
||||||
ARG obsidian_vault=/home/venus/Documents/Personal-Wiki
|
|
||||||
ARG OBSIDIAN_VAULT_URL=git.riverrooks.dev/venus/Personal-Wiki
|
|
||||||
ARG obsidian_vault_token=bd8cd9301ae2c1c5bacfb3340492acb5e862686a
|
|
||||||
|
|
||||||
ENV FLASK_DEBUG=$DEBUG_MODE
|
ENV FLASK_DEBUG=$DEBUG_MODE
|
||||||
ENV FLASK_APP=app
|
ENV FLASK_APP=app
|
||||||
# ENV OBSIDIAN_VAULT=$obsidian_vault
|
|
||||||
ENV OBSIDIAN_VAULT_URL=$OBSIDIAN_VAULT_URL
|
RUN mkdir /app
|
||||||
ENV OBSIDIAN_VAULT_TOKEN=$obsidian_vault_token
|
COPY app/requirements.txt /app
|
||||||
|
RUN pip3 install -r /app/requirements.txt
|
||||||
|
|
||||||
COPY app /app
|
COPY app /app
|
||||||
|
|
||||||
|
|||||||
@@ -2,23 +2,22 @@ from flask import Flask
|
|||||||
from app import build
|
from app import build
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import markdown
|
import markdown
|
||||||
import os
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
PRIVATE_VAULT_DIR = Path("/vault")
|
CONTENT_DIR = Path("/content")
|
||||||
PUBLIC_VAULT_DIR = "/content"
|
|
||||||
|
|
||||||
build.obsidian_vault(PRIVATE_VAULT_DIR) # initialize the private obsidian repo
|
|
||||||
# build.public_vault(PUBLIC_VAULT_DIR) # initialize the public notes from the private repo
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
|
# Write your markdown content
|
||||||
md_content = "# Welcome to my blog!\nThis is rendered from **Markdown**.\n##[test](http://localhost/test)"
|
md_content = "# Welcome to my blog!\nThis is rendered from **Markdown**.\n##[test](http://localhost/test)"
|
||||||
|
# Convert it to HTML
|
||||||
html_content = markdown.markdown(md_content)
|
html_content = markdown.markdown(md_content)
|
||||||
return html_content
|
return html_content
|
||||||
|
|
||||||
@app.route ("/<filename>") # renders a filename if not otherwise specified
|
@app.route ("/<filename>")
|
||||||
def render_post(filename):
|
def render_post(filename):
|
||||||
return build.html_file(filename, PUBLIC_VAULT_DIR)
|
return build.render_file(filename, CONTENT_DIR)
|
||||||
|
# return "test"
|
||||||
|
|
||||||
|
# return rm(filename)
|
||||||
|
|||||||
58
app/build.py
58
app/build.py
@@ -2,10 +2,9 @@ from obsidian_parser import Vault
|
|||||||
import shutil
|
import shutil
|
||||||
import markdown
|
import markdown
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def html_file(filename: str, contentPath: Path): #renders markwown from filename
|
def render_file(filename: str, contentPath: Path): #renders markwown from filename
|
||||||
filePath = contentPath / f"{filename}.md"
|
filePath = contentPath / f"{filename}.md"
|
||||||
# 3. Protect against missing files
|
# 3. Protect against missing files
|
||||||
if not filePath.is_file():
|
if not filePath.is_file():
|
||||||
@@ -17,45 +16,24 @@ def html_file(filename: str, contentPath: Path): #renders markwown from filename
|
|||||||
htmlContent = markdown.markdown(textContent)
|
htmlContent = markdown.markdown(textContent)
|
||||||
return htmlContent
|
return htmlContent
|
||||||
|
|
||||||
|
print("build imported")
|
||||||
|
# def clone_gittea_repo(url: str, token: str = "", dest: str): # clone a gittea repo using optional security token into dest dirand return a path to the directory
|
||||||
|
# return dest
|
||||||
|
|
||||||
def obsidian_vault(dest = "/vault"): # makes sure there is a vault in dest
|
# def public_notes(src: str): # return a list of notes tagged with public from an obsidian directory
|
||||||
from git import Repo
|
# # build vault from source
|
||||||
url = os.getenv("OBSIDIAN_VAULT_URL")
|
# vault = Vault(src)
|
||||||
token = os.getenv("OBSIDIAN_VAULT_TOKEN")
|
# if vault:
|
||||||
if not(token):
|
# print ("found vault")
|
||||||
print ("token not found, cant build vault")
|
# else:
|
||||||
raise NameError("tokenNotFound")
|
# print("could not find vault")
|
||||||
return 0
|
# return []
|
||||||
|
|
||||||
url = f"https://{token}@{url}"
|
# # return a list ofnotes
|
||||||
|
# return vault.get_notes_with_tag("public")
|
||||||
if os.path.exists(os.path.join(dest, '.git')):
|
|
||||||
#TODO handle merge conflictsjjj
|
|
||||||
print (f"pulling vault from {url} in {dest}")
|
|
||||||
repo = Repo(dest)
|
|
||||||
origin = repo.remotes.origin
|
|
||||||
origin.fetch()
|
|
||||||
origin.pull(strategy_option='theirs')
|
|
||||||
print ("vault updated")
|
|
||||||
return 1
|
|
||||||
|
|
||||||
print (f"building vault from {url} in {dest}")
|
|
||||||
Repo.clone_from(url, dest)
|
|
||||||
print("cloned vault!")
|
|
||||||
return 1
|
|
||||||
|
|
||||||
def public_notes(src: str): # return a list of notes tagged with public from an obsidian directory
|
|
||||||
# build vault object from source
|
|
||||||
vault = Vault(src)
|
|
||||||
if not(vault):
|
|
||||||
print("could not find vault")
|
|
||||||
raise NameError("vaultNotFound")
|
|
||||||
return []
|
|
||||||
# return a list of notes
|
|
||||||
return vault.get_notes_with_tag("public")
|
|
||||||
|
|
||||||
|
|
||||||
def public_vault(dest: str, src: str = "/content"): # build the public vault in dest from an obsidian repo in src
|
# def buld_public_vault(src: str, dest: str): # build the public vault in dest from an obsidian repo in src
|
||||||
for note in public_notes(src):
|
# for note in public_notes(src):
|
||||||
print(note.title)
|
# print(note.title)
|
||||||
shutil.copy2(f"{note.path}", dest)
|
# shutil.copy2(f"{note.path}", dest)
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ flask
|
|||||||
markdown
|
markdown
|
||||||
obsidianmd-parser
|
obsidianmd-parser
|
||||||
GitPython
|
GitPython
|
||||||
python-dotenv
|
py-gitea
|
||||||
|
|||||||
11
compose.yml
11
compose.yml
@@ -3,11 +3,12 @@ services:
|
|||||||
build:
|
build:
|
||||||
args:
|
args:
|
||||||
- DEBUG_MODE=1
|
- DEBUG_MODE=1
|
||||||
- obsidian_vault_url=https://git.riverrooks.dev/Personal-Wiki
|
|
||||||
- obsidian_vault_token=bd8cd9301ae2c1c5bacfb3340492acb5e862686a
|
|
||||||
|
|
||||||
ports:
|
ports:
|
||||||
- '80:80'
|
- '80:80'
|
||||||
volumes:
|
volumes:
|
||||||
- ./content:/content #public
|
- ./content:/content
|
||||||
- ./public-vault:/vault #private
|
# public_vault_builder:
|
||||||
|
# build:
|
||||||
|
# context: public_vault_builder
|
||||||
|
# volumes:
|
||||||
|
# - ./public_vault:/content
|
||||||
|
|||||||
Reference in New Issue
Block a user