Compare commits
7 Commits
dev
...
e9b1a95b9a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9b1a95b9a | ||
|
|
48d27184be | ||
|
|
c41f3a0286 | ||
|
|
d6a1d30747 | ||
|
|
35f0edbc83 | ||
|
|
f22fb410ab | ||
|
|
58e972e65f |
3
.env
3
.env
@@ -1,4 +1,5 @@
|
|||||||
obsidian_vault=/home/venus/Documents/Personal-Wiki
|
obsidian_vault=/home/venus/Documents/Personal-Wiki
|
||||||
obsidian_vault_url=https://git.riverrooks.dev/Personal-Wiki
|
obsidian_vault_url=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 +1,2 @@
|
|||||||
app/__pychache__
|
app/__pychache__
|
||||||
|
public-vault
|
||||||
|
|||||||
23
Dockerfile
23
Dockerfile
@@ -1,13 +1,26 @@
|
|||||||
FROM python:3.14-slim
|
FROM python:3.14-slim
|
||||||
|
|
||||||
ARG DEBUG_MODE=0
|
#install git
|
||||||
ENV FLASK_DEBUG=$DEBUG_MODE
|
RUN apt-get update && apt-get install -y \
|
||||||
ENV FLASK_APP=app
|
git \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
RUN mkdir /app
|
#install dependencies
|
||||||
|
RUN mkdir /app
|
||||||
COPY app/requirements.txt /app
|
COPY app/requirements.txt /app
|
||||||
RUN pip3 install -r /app/requirements.txt
|
RUN pip3 install -r /app/requirements.txt
|
||||||
|
|
||||||
|
#parse from .env file
|
||||||
|
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_APP=app
|
||||||
|
# ENV OBSIDIAN_VAULT=$obsidian_vault
|
||||||
|
ENV OBSIDIAN_VAULT_URL=$OBSIDIAN_VAULT_URL
|
||||||
|
ENV OBSIDIAN_VAULT_TOKEN=$obsidian_vault_token
|
||||||
|
|
||||||
COPY app /app
|
COPY app /app
|
||||||
|
|
||||||
ENTRYPOINT ["flask"]
|
ENTRYPOINT ["flask"]
|
||||||
|
|||||||
@@ -2,22 +2,23 @@ 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__)
|
||||||
|
|
||||||
CONTENT_DIR = Path("/content")
|
PRIVATE_VAULT_DIR = Path("/vault")
|
||||||
|
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>")
|
@app.route ("/<filename>") # renders a filename if not otherwise specified
|
||||||
def render_post(filename):
|
def render_post(filename):
|
||||||
return build.render_file(filename, CONTENT_DIR)
|
return build.html_file(filename, PUBLIC_VAULT_DIR)
|
||||||
# return "test"
|
|
||||||
|
|
||||||
# return rm(filename)
|
|
||||||
|
|||||||
58
app/build.py
58
app/build.py
@@ -2,9 +2,10 @@ from obsidian_parser import Vault
|
|||||||
import shutil
|
import shutil
|
||||||
import markdown
|
import markdown
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def render_file(filename: str, contentPath: Path): #renders markwown from filename
|
def html_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():
|
||||||
@@ -16,24 +17,45 @@ def render_file(filename: str, contentPath: Path): #renders markwown from filena
|
|||||||
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 public_notes(src: str): # return a list of notes tagged with public from an obsidian directory
|
def obsidian_vault(dest = "/vault"): # makes sure there is a vault in dest
|
||||||
# # build vault from source
|
from git import Repo
|
||||||
# vault = Vault(src)
|
url = os.getenv("OBSIDIAN_VAULT_URL")
|
||||||
# if vault:
|
token = os.getenv("OBSIDIAN_VAULT_TOKEN")
|
||||||
# print ("found vault")
|
if not(token):
|
||||||
# else:
|
print ("token not found, cant build vault")
|
||||||
# print("could not find vault")
|
raise NameError("tokenNotFound")
|
||||||
# return []
|
return 0
|
||||||
|
|
||||||
# # return a list ofnotes
|
url = f"https://{token}@{url}"
|
||||||
# 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 buld_public_vault(src: str, dest: str): # build the public vault in dest from an obsidian repo in src
|
def public_vault(dest: str, src: str = "/content"): # 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
|
||||||
py-gitea
|
python-dotenv
|
||||||
|
|||||||
11
compose.yml
11
compose.yml
@@ -3,12 +3,11 @@ 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
|
- ./content:/content #public
|
||||||
# public_vault_builder:
|
- ./public-vault:/vault #private
|
||||||
# build:
|
|
||||||
# context: public_vault_builder
|
|
||||||
# volumes:
|
|
||||||
# - ./public_vault:/content
|
|
||||||
|
|||||||
Reference in New Issue
Block a user