-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompts.html
More file actions
71 lines (66 loc) · 2.69 KB
/
Copy pathprompts.html
File metadata and controls
71 lines (66 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prompts Documentation</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.5.0/github-markdown.min.css">
<style>
body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
}
@media (max-width: 767px) {
body { padding: 15px; }
}
</style>
</head>
<body class="markdown-body">
<div id="content">Loading documentation...</div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
const urlParams = new URLSearchParams(window.location.search);
let targetPage = urlParams.get('page') || 'README.md';
const folderPath = 'Prompts/';
// Use a Custom Renderer to intercept links DURING parsing so they never break
const renderer = {
link({ href, title, text }) {
// If the link is a relative markdown file link (ends with .md and isn't a web URL)
if (href && href.endsWith('.md') && !href.startsWith('http') && !href.startsWith('//')) {
// Extract just the filename if it accidentally included folder paths
const fileName = href.split('/').pop();
return `<a href="prompts.html?page=${fileName}" title="${title || ''}">${text}</a>`;
}
// Leave standard website links alone
return `<a href="${href}" title="${title || ''}">${text}</a>`;
}
};
marked.use({ renderer });
marked.setOptions({
breaks: true,
gfm: true
});
// Fetch the file from the Prompts folder
fetch(folderPath + targetPage)
.then(response => {
if (!response.ok) throw new Error('Page not found');
return response.text();
})
.then(text => {
// Parse markdown and throw it to the page
document.getElementById('content').innerHTML = marked.parse(text);
document.title = targetPage.replace('.md', '').toUpperCase();
})
.catch(err => {
document.getElementById('content').innerHTML = `
<h2>404: Page Not Found</h2>
<p>Could not locate: <code>${folderPath}${targetPage}</code></p>
<p><a href="prompts.html?page=README.md">← Back to Prompts Home</a></p>
`;
});
</script>
</body>
</html>