Compare commits
17 Commits
fix-docker
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
427c3b6427 | ||
|
|
13d7676ff4 | ||
|
|
e9b1a95b9a | ||
|
|
48d27184be | ||
|
|
c41f3a0286 | ||
|
|
d6a1d30747 | ||
|
|
35f0edbc83 | ||
|
|
f22fb410ab | ||
|
|
58e972e65f | ||
|
|
bacbd48d30 | ||
|
|
62dcfab912 | ||
|
|
6c6cccae49 | ||
|
|
7612837e82 | ||
|
|
fdbced9192 | ||
|
|
99a0df522e | ||
|
|
1b177e3d86 | ||
|
|
d3c8d6e544 |
3
.env
3
.env
@@ -1,2 +1,5 @@
|
||||
obsidian_vault=/home/venus/Documents/Personal-Wiki
|
||||
obsidian_vault_url=git.riverrooks.dev/Personal-Wiki
|
||||
OBSIDIAN_VAULT_URL=git.riverrooks.dev/Personal-Wiki
|
||||
obsidian_vault_token=bd8cd9301ae2c1c5bacfb3340492acb5e862686a
|
||||
|
||||
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
app/__pychache__
|
||||
public-vault
|
||||
29
Dockerfile
Executable file
29
Dockerfile
Executable file
@@ -0,0 +1,29 @@
|
||||
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 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
|
||||
|
||||
ENTRYPOINT ["flask"]
|
||||
CMD ["run", "--host=0.0.0.0", "--port=80"]
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
FROM python:3.10-slim AS builder
|
||||
|
||||
ARG DEBUG_MODE=0
|
||||
ENV FLASK_DEBUG=$DEBUG_MODE
|
||||
ENV FLASK_APP=app
|
||||
|
||||
|
||||
|
||||
COPY requirements.txt
|
||||
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
|
||||
EXPOSE 443
|
||||
ENTRYPOINT ["flask"]
|
||||
# CMD [ "run", "--host=0.0.0.0", "--port=80"]
|
||||
CMD ["--app", "app", "run", "--host=0.0.0.0", "--port=443"]
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
from flask import Flask
|
||||
import markdown
|
||||
from pathlib import Path
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
CONTENT_DIR = Path(__file__).parent.parent / "content"
|
||||
|
||||
@app.route("/hello")
|
||||
def hello_world():
|
||||
return "<h1>Hello, World!</h1>"
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
# Write your markdown content
|
||||
md_content = "# Welcome to my blog!\nThis is rendered from **Markdown**."
|
||||
# Convert it to HTML
|
||||
html_content = markdown.markdown(md_content)
|
||||
return html_content
|
||||
|
||||
@app.route ("/post/<filename>")
|
||||
def render_markdown_file(filename):
|
||||
filePath = CONTENT_DIR / f"{filename}.md"
|
||||
# 3. Protect against missing files
|
||||
if not filePath.is_file():
|
||||
return f"<h1>404</h1><p>Could not find {filename}.md in {filePath}</p>", 404
|
||||
# else:
|
||||
# return f"<h1> found</h1> <p> found {filename} in {filePath}</p>"
|
||||
# 4. Open, read, and convert the file
|
||||
with open(filePath, "r", encoding="utf-8") as f:
|
||||
textContent = f.read()
|
||||
|
||||
htmlContent = markdown.markdown(textContent)
|
||||
|
||||
return htmlContent
|
||||
26
app/__init__.py
Normal file
26
app/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from flask import Flask
|
||||
from app import build
|
||||
from pathlib import Path
|
||||
import markdown
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
PRIVATE_VAULT_DIR = Path("/vault")
|
||||
PUBLIC_VAULT_DIR = "/content"
|
||||
|
||||
build.obsidian_vault(PRIVATE_VAULT_DIR) # initialize the private obsidian repo
|
||||
build.public_vault(PRIVATE_VAULT_DIR, PUBLIC_VAULT_DIR) # initialize the public notes from the private repo
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
md_content = "# Welcome to my blog!\nThis is rendered from **Markdown**.\n##[test](http://localhost/test)"
|
||||
html_content = markdown.markdown(md_content)
|
||||
return html_content
|
||||
@app.route("/api/push") #webhook for vault updated
|
||||
def
|
||||
|
||||
@app.route ("/<filename>") # renders a filename if not otherwise specified
|
||||
def render_post(filename):
|
||||
return build.html_file(filename, PUBLIC_VAULT_DIR)
|
||||
61
app/build.py
61
app/build.py
@@ -1,26 +1,61 @@
|
||||
from obsidian_parser import Vault
|
||||
import shutil
|
||||
import markdown
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
|
||||
def html_file(filename, contentPath): #renders markwown from filename
|
||||
filePath = Path(f"{contentPath}/{filename}.md")
|
||||
# 3. Protect against missing files
|
||||
if not filePath.is_file():
|
||||
return f"<h1>404</h1><p>Could not find {filename}.md in {filePath}</p>", 404
|
||||
# open the file for reading
|
||||
with open(filePath, "r", encoding="utf-8") as f:
|
||||
textContent = f.read()
|
||||
# convert it to markdown
|
||||
htmlContent = markdown.markdown(textContent)
|
||||
return htmlContent
|
||||
|
||||
|
||||
def obsidian_vault(dest = "/vault"): # makes sure there is a vault in dest
|
||||
from git import Repo
|
||||
url = os.getenv("OBSIDIAN_VAULT_URL")
|
||||
token = os.getenv("OBSIDIAN_VAULT_TOKEN")
|
||||
if not(token):
|
||||
print ("token not found, cant build vault")
|
||||
raise NameError("tokenNotFound")
|
||||
return 0
|
||||
|
||||
url = f"https://{token}@{url}"
|
||||
|
||||
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
|
||||
|
||||
def clone_secure_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
|
||||
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 from source
|
||||
vault = Vault(src)
|
||||
if vault:
|
||||
print ("found vault")
|
||||
else:
|
||||
def public_vault(privateVault = "/vault", dest = "/content"): # build the public vault in dest from an obsidian repo in src
|
||||
vault = Vault(privateVault)
|
||||
if not(vault):
|
||||
print("could not find vault")
|
||||
return []
|
||||
raise NameError("vaultNotFound")
|
||||
return 0
|
||||
|
||||
# return a list ofnotes
|
||||
return vault.get_notes_with_tag("public")
|
||||
print(f"valid vault{vault}")
|
||||
|
||||
publicNotes = 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
|
||||
for note in public_notes(src):
|
||||
print(f"publicNotes: {publicNotes}")
|
||||
for note in publicNotes:
|
||||
print(note.title)
|
||||
shutil.copy2(f"{note.path}", dest)
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
flask
|
||||
markdown
|
||||
obsidianmd-parser
|
||||
GitPython
|
||||
python-dotenv
|
||||
|
||||
12
compose.yml
12
compose.yml
@@ -1,15 +1,13 @@
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: app
|
||||
args:
|
||||
- DEBUG_MODE=1
|
||||
- obsidian_vault_url=https://git.riverrooks.dev/Personal-Wiki
|
||||
- obsidian_vault_token=bd8cd9301ae2c1c5bacfb3340492acb5e862686a
|
||||
|
||||
ports:
|
||||
- '80:80'
|
||||
volumes:
|
||||
- ./content:/content
|
||||
# public_vault_builder:
|
||||
# build:
|
||||
# context: public_vault_builder
|
||||
# volumes:
|
||||
# - ./public_vault:/content
|
||||
- ./content:/content #public
|
||||
- ./public-vault:/vault #private
|
||||
|
||||
10
content/test.md
Executable file → Normal file
10
content/test.md
Executable file → Normal file
@@ -1,3 +1,11 @@
|
||||
---
|
||||
public: "true"
|
||||
tags:
|
||||
- public
|
||||
---
|
||||
# This is a test
|
||||
and this is p
|
||||
*italics*
|
||||
[https://localhost/test]()
|
||||
[asd](https://localhost/test)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
---
|
||||
public: "true"
|
||||
tags:
|
||||
- public
|
||||
---
|
||||
# This is a test
|
||||
and this is p
|
||||
@@ -1,14 +0,0 @@
|
||||
FROM python:3.12-slim
|
||||
|
||||
|
||||
run mkdir /public-vault
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
COPY requirements.txt .
|
||||
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["python", "build.py"]
|
||||
@@ -1,25 +0,0 @@
|
||||
from obsidian_parser import Vault
|
||||
import shutil
|
||||
from git import Repo
|
||||
|
||||
|
||||
# repo_url = "https://gitlab.com/username/my-vault.git"
|
||||
dest = "/content"
|
||||
src = "Personal-Wiki"
|
||||
# Load a vault
|
||||
vault = Vault(src)
|
||||
|
||||
if vault:
|
||||
print ("found vault")
|
||||
else:
|
||||
print("could not find vault")
|
||||
|
||||
# Find notes by exact name
|
||||
note = vault.get_note("test")
|
||||
|
||||
# Findd all public notes
|
||||
publicNotes = vault.get_notes_with_tag("public")
|
||||
|
||||
for note in publicNotes:
|
||||
print(note.title)
|
||||
shutil.copy2(f"{note.path}", dest)
|
||||
@@ -1,2 +0,0 @@
|
||||
obsidianmd-parser
|
||||
GitPython
|
||||
Reference in New Issue
Block a user