-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35c5b19
commit 9de3400
Showing
9 changed files
with
218 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,92 @@ | ||
<template> | ||
<div class="flex flex-col w-[calc(100vw-10px)] justify-center items-center"> | ||
<div class="max-w-7xl w-full flex"> | ||
<div class="w-full flex mx-2 bg-gray-200 rounded-t"> | ||
<button @click="updateFile" class="bg-green-200 text-slate-800 hover:brightness-95 active:brightness-90 px-3 py-2 rounded my-2 ml-auto mr-2">Update</button> | ||
<div class="flex w-[calc(100vw-10px)] flex-col items-center justify-center"> | ||
<div class="flex w-full max-w-7xl"> | ||
<div class="mx-2 flex w-full rounded-t bg-gray-200"> | ||
<button | ||
class="my-2 ml-auto mr-2 rounded bg-green-200 px-3 py-2 text-slate-800 hover:brightness-95 active:brightness-90" | ||
@click="updateFile" | ||
> | ||
Update | ||
</button> | ||
</div> | ||
</div> | ||
<div class="max-w-7xl px-2 grid grid-rows-2 xl:grid-rows-1 xl:grid-cols-2 max-h-[820px] overflow-auto"> | ||
<MonacoEditor lang="markdown" class="flex-grow max-h-[820px] border overflow-auto" v-model="inputText" | ||
placeholder="Enter text to render" /> | ||
<MDC class="flex-grow max-h-[820px] border overflow-auto" :value="processedInputText"></MDC> | ||
<div | ||
class="grid max-h-[820px] max-w-7xl grid-rows-2 overflow-auto px-2 xl:grid-cols-2 xl:grid-rows-1" | ||
> | ||
<MonacoEditor | ||
v-model="inputText" | ||
lang="markdown" | ||
class="max-h-[820px] flex-grow overflow-auto border" | ||
placeholder="Enter text to render" | ||
/> | ||
<MDC | ||
class="max-h-[820px] flex-grow overflow-auto border" | ||
:value="processedInputText" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
definePageMeta({ | ||
layout: 'admin' | ||
}) | ||
import { ref, onMounted } from 'vue'; | ||
import { ref, onMounted } from 'vue' | ||
const inputText = ref('# loading...') | ||
const route = useRoute() | ||
const path = route.path | ||
const stripedPath = path.replace(/^\/admin/, ''); | ||
const sha = ref('') | ||
const articleUrl = 'https://api.github.com/repos/hanyujie2002/Vardar-Nuxt-Blog/contents/content' + '/about' + '.md?ref=main' | ||
const token = localStorage.getItem('github-token') | ||
definePageMeta({ | ||
layout: 'admin', | ||
}); | ||
const inputText = ref('# loading...'); | ||
const sha = ref(''); | ||
const articleUrl = | ||
'https://api.github.com/repos/hanyujie2002/Vardar-Nuxt-Blog/contents/content' + | ||
'/about' + | ||
'.md?ref=main'; | ||
const token = localStorage.getItem('github-token'); | ||
onMounted(async () => { | ||
const response = await fetch(articleUrl, { | ||
headers: { | ||
'Authorization': `token ${token}`, | ||
Authorization: `token ${token}`, | ||
}, | ||
cache: 'no-cache' | ||
}) | ||
cache: 'no-cache', | ||
}); | ||
const data = await response.json() | ||
const data = await response.json(); | ||
sha.value = data.sha; | ||
const base64Content = data.content | ||
const decodedContent = new TextDecoder('utf-8').decode(Uint8Array.from(atob(base64Content), c => c.charCodeAt(0))) | ||
const base64Content = data.content; | ||
const decodedContent = new TextDecoder('utf-8').decode( | ||
Uint8Array.from(atob(base64Content), (c) => c.charCodeAt(0)) | ||
); | ||
inputText.value = decodedContent | ||
}) | ||
inputText.value = decodedContent; | ||
}); | ||
const processedInputText = computed(() => inputText.value.length > 0 ? inputText.value : 'No content yet'); | ||
const processedInputText = computed(() => | ||
inputText.value.length > 0 ? inputText.value : 'No content yet' | ||
); | ||
const updateFile = async () => { | ||
const updatedContent = new TextEncoder().encode(inputText.value); | ||
const base64Content = btoa(String.fromCharCode(...new Uint8Array(updatedContent))) | ||
const base64Content = btoa( | ||
String.fromCharCode(...new Uint8Array(updatedContent)) | ||
); | ||
const response = await fetch(articleUrl, { | ||
method: 'PUT', | ||
headers: { | ||
'Authorization': `token ${token}`, | ||
Authorization: `token ${token}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
message: 'Test: Updating blog content', | ||
content: base64Content, | ||
sha: sha.value, | ||
}) | ||
}) | ||
}), | ||
}); | ||
if (response.ok) { | ||
console.log('File updated successfully!') | ||
console.log('File updated successfully!'); | ||
} else { | ||
console.error('File update failed', response.statusText) | ||
console.error('File update failed', response.statusText); | ||
} | ||
} | ||
}; | ||
</script> | ||
|
Oops, something went wrong.