Compare commits
6 Commits
58e972e65f
...
e9b1a95b9a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9b1a95b9a | ||
|
|
48d27184be | ||
|
|
c41f3a0286 | ||
|
|
d6a1d30747 | ||
|
|
35f0edbc83 | ||
|
|
f22fb410ab |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
app/__pychache__
|
||||
public-vault
|
||||
|
||||
@@ -5,30 +5,20 @@ import markdown
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
vault_path = os.getenv("VAULT_PATH", "/vault") # Optional default value
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
CONTENT_DIR = Path("/content")
|
||||
VAULT_DIR = "/vault"
|
||||
|
||||
build.obsidian_vault(VAULT_DIR)
|
||||
# Find obsidian vault path or clone it
|
||||
# if not os.path.exists(VAULT_DIR):
|
||||
# # print(os.getenv("OBSIDIAN_VAULT_URL"))
|
||||
# build.clone_gittea_repo(os.getenv("OBSIDIAN_VAULT_URL"), VAULT_DIR, os.getenv("OBSIDIAN_VALUT_TOKEN"))
|
||||
# else:
|
||||
# print("vault already exists")
|
||||
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("/")
|
||||
def index():
|
||||
# Write your markdown content
|
||||
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)
|
||||
return html_content
|
||||
|
||||
@app.route ("/<filename>") # renders a filename if not otherwise specified
|
||||
def render_post(filename):
|
||||
return build.render_file(filename, CONTENT_DIR)
|
||||
return build.html_file(filename, PUBLIC_VAULT_DIR)
|
||||
|
||||
45
app/build.py
45
app/build.py
@@ -5,7 +5,7 @@ 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"
|
||||
# 3. Protect against missing files
|
||||
if not filePath.is_file():
|
||||
@@ -17,36 +17,45 @@ def render_file(filename: str, contentPath: Path): #renders markwown from filena
|
||||
htmlContent = markdown.markdown(textContent)
|
||||
return htmlContent
|
||||
|
||||
def obsidian_vault(dest = "/vault"): # makes sure there is a vault in dest
|
||||
if os.path.exists(dest):
|
||||
return "vault exists"
|
||||
|
||||
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
|
||||
|
||||
if token:
|
||||
print ("token found")
|
||||
url = f"https://{token}@{url}"
|
||||
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
|
||||
|
||||
print (f"building vault from {url} in {dest}")
|
||||
Repo.clone_from(url, dest)
|
||||
print("finished vault!")
|
||||
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
|
||||
# build vault object from source
|
||||
vault = Vault(src)
|
||||
if vault:
|
||||
print ("found vault")
|
||||
else:
|
||||
if not(vault):
|
||||
print("could not find vault")
|
||||
raise NameError("vaultNotFound")
|
||||
return []
|
||||
|
||||
# return a list ofnotes
|
||||
# return a list of notes
|
||||
return vault.get_notes_with_tag("public")
|
||||
|
||||
|
||||
# def public_vault(dest: str, url = "", token = ""): # build the public vault in dest from an obsidian repo in src
|
||||
# for note in public_notes(src):
|
||||
# print(note.title)
|
||||
# shutil.copy2(f"{note.path}", dest)
|
||||
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):
|
||||
print(note.title)
|
||||
shutil.copy2(f"{note.path}", dest)
|
||||
|
||||
@@ -9,10 +9,5 @@ services:
|
||||
ports:
|
||||
- '80:80'
|
||||
volumes:
|
||||
- ./content:/content
|
||||
# - /home/venus/Documents/Personal-Wiki:/vault
|
||||
# public_vault_builder:
|
||||
# build:
|
||||
# context: public_vault_builder
|
||||
# volumes:
|
||||
# - ./public_vault:/content
|
||||
- ./content:/content #public
|
||||
- ./public-vault:/vault #private
|
||||
|
||||
Reference in New Issue
Block a user