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__
|
app/__pychache__
|
||||||
|
public-vault
|
||||||
|
|||||||
@@ -5,30 +5,20 @@ import markdown
|
|||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
vault_path = os.getenv("VAULT_PATH", "/vault") # Optional default value
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
CONTENT_DIR = Path("/content")
|
PRIVATE_VAULT_DIR = Path("/vault")
|
||||||
VAULT_DIR = "/vault"
|
PUBLIC_VAULT_DIR = "/content"
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
|
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>") # 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)
|
||||||
|
|||||||
45
app/build.py
45
app/build.py
@@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
import os
|
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():
|
||||||
@@ -17,36 +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
|
||||||
|
|
||||||
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
|
from git import Repo
|
||||||
url = os.getenv("OBSIDIAN_VAULT_URL")
|
url = os.getenv("OBSIDIAN_VAULT_URL")
|
||||||
token = os.getenv("OBSIDIAN_VAULT_TOKEN")
|
token = os.getenv("OBSIDIAN_VAULT_TOKEN")
|
||||||
|
if not(token):
|
||||||
|
print ("token not found, cant build vault")
|
||||||
|
raise NameError("tokenNotFound")
|
||||||
|
return 0
|
||||||
|
|
||||||
if token:
|
url = f"https://{token}@{url}"
|
||||||
print ("token found")
|
|
||||||
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}")
|
print (f"building vault from {url} in {dest}")
|
||||||
Repo.clone_from(url, 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
|
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)
|
vault = Vault(src)
|
||||||
if vault:
|
if not(vault):
|
||||||
print ("found vault")
|
|
||||||
else:
|
|
||||||
print("could not find vault")
|
print("could not find vault")
|
||||||
|
raise NameError("vaultNotFound")
|
||||||
return []
|
return []
|
||||||
|
# return a list of notes
|
||||||
# return a list ofnotes
|
|
||||||
return vault.get_notes_with_tag("public")
|
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
|
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)
|
||||||
|
|||||||
@@ -9,10 +9,5 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- '80:80'
|
- '80:80'
|
||||||
volumes:
|
volumes:
|
||||||
- ./content:/content
|
- ./content:/content #public
|
||||||
# - /home/venus/Documents/Personal-Wiki:/vault
|
- ./public-vault:/vault #private
|
||||||
# public_vault_builder:
|
|
||||||
# build:
|
|
||||||
# context: public_vault_builder
|
|
||||||
# volumes:
|
|
||||||
# - ./public_vault:/content
|
|
||||||
|
|||||||
Reference in New Issue
Block a user