implemented public vault initialization
This commit is contained in:
@@ -9,10 +9,11 @@ vault_path = os.getenv("VAULT_PATH", "/vault") # Optional default value
|
|||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
CONTENT_DIR = Path("/content")
|
PRIVATE_VAULR_DIR = Path("/content")
|
||||||
VAULT_DIR = "/vault"
|
PUBLIC_VAULT_DIR = "/vault"
|
||||||
|
|
||||||
build.obsidian_vault(VAULT_DIR)
|
build.obsidian_vault(VAULT_DIR) # initialize the private obsidian repo
|
||||||
|
build.public_vault(VAULT_DIR) # initialize the public notes from the private repo
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
|
|||||||
36
app/build.py
36
app/build.py
@@ -17,42 +17,42 @@ def html_file(filename: str, contentPath: Path): #renders markwown from filename
|
|||||||
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
|
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")
|
||||||
if token:
|
raise NameError("tokenNotFound")
|
||||||
print ("token found")
|
return 0
|
||||||
url = f"https://{token}@{url}"
|
url = f"https://{token}@{url}"
|
||||||
|
|
||||||
if os.path.exists(os.path.join(dest, '.git')):
|
if os.path.exists(os.path.join(dest, '.git')):
|
||||||
|
#TODO handle merge conflictsjjj
|
||||||
print (f"pulling vault from {url} in {dest}")
|
print (f"pulling vault from {url} in {dest}")
|
||||||
repo = Repo(dest)
|
repo = Repo(dest)
|
||||||
origin = repo.remotes.origin
|
origin = repo.remotes.origin
|
||||||
origin.pull()
|
origin.fetch()
|
||||||
|
origin.pull(strategy_option='theirs')
|
||||||
|
print ("vault updated")
|
||||||
return 1
|
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
|
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): # build the public vault in dest from an obsidian repo in src
|
||||||
# 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):
|
||||||
# for note in public_notes(src):
|
print(note.title)
|
||||||
# print(note.title)
|
shutil.copy2(f"{note.path}", dest)
|
||||||
# shutil.copy2(f"{note.path}", dest)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user