Skip to content

Commit a642955

Browse files
committed
Make discord webhook url into an environment variable using github repo secret, might not work. Defer scripts and only use them on relevant pages.
1 parent 06434ee commit a642955

File tree

9 files changed

+25
-12
lines changed

9 files changed

+25
-12
lines changed

.github/workflows/gh-pages.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ jobs:
2222
# extended: true
2323

2424
- name: Build
25-
run: hugo --minify
25+
run: DISCORD_WEBHOOK_URL=$DISCORD_WEBHOOK_URL hugo --minify
26+
env:
27+
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
2628

2729
- name: Deploy
2830
uses: peaceiris/actions-gh-pages@v3

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ public/
88
__pycache__/
99
*.py[cod]
1010
pynecone.db
11-
.web
11+
.web
12+
.env

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The first command runs the site, and the second monitors for file changes to syn
4141

4242
4. If you ran the docker compose command you should also have a Python applet I wrote up at `localhost:8501` in your browser. This is a GUI that helps you write the tedious parts of a formula's page. You can read more about it in the ChatGPT workflow section at the bottom of this README.
4343

44+
5. If you want to test the submitting to Discord feature, crete a `.env` file in the root directory of the repository with DISCORD_WEBHOOK_URL=<your webhook link>
4445

4546
## Adding a formula
4647
With the site running locally, you can now add a formula page to the site and preview how it'll look on the actual site.

assets/js/formula-suggest.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ function sanitizeInput(input) {
5959
const latex = sanitizeInput(document.getElementById('latex').value);
6060
const body = sanitizeInput(document.getElementById('body').value);
6161

62-
const webhookURL = 'https://discord.com/api/webhooks/1059998584889688134/eUqXbInp90bcFdL1A3ly141TAtn9jiPjbYwCzSfjPV2-4kx2UIX3M-soCJxWTrvSNbLP'; // Replace with your Discord webhook URL
63-
6462
const data = {
6563
embeds: [
6664
{
@@ -97,7 +95,7 @@ function sanitizeInput(input) {
9795
],
9896
};
9997

100-
fetch(webhookURL, {
98+
fetch(webhook_url, {
10199
method: 'POST',
102100
headers: {
103101
'Content-Type': 'application/json',

config/_default/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ googleAnalytics= "G-055HWG7Q3V"
1616
[imaging]
1717
resampleFilter = "lanczos"
1818
quality = 100
19+
20+
[security]
21+
enableInlineShortcodes = false
22+
[security.funcs]
23+
getenv = ["DISCORD_WEBHOOK_URL"]
24+

docker-compose.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ services:
44
build: .
55
ports:
66
- "1313:1313"
7-
x-develop:
7+
develop:
88
watch:
99
- action: sync
1010
path: .
1111
target: /src/
12+
env_file:
13+
- .env
14+
1215
streamlit:
1316
build:
1417
context: .
1518
dockerfile: Dockerfile-streamlit
1619
ports:
1720
- "8501:8501"
18-
x-develop:
21+
develop:
1922
watch:
2023
- action: sync
2124
path: ./streamlit-app.py

layouts/_default/submit.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ <h2 class="mb-6 text-2xl font-bold text-neutral-900 dark:text-neutral">Preview</
127127
</button>
128128
</section>
129129
</article>
130-
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.2.3/purify.min.js"></script>
130+
<!-- get the webhook url from the environment using hugo, don't know how to do it in js.-->
131+
<script>
132+
const webhook_url = "{{ getenv "DISCORD_WEBHOOK_URL" }}"; // '' doesn't work
133+
</script>
134+
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.2.3/purify.min.js"></script>
135+
<script defer src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
131136
{{ $js := resources.Get "js/formula-suggest.js" | fingerprint }}
132137
<script src="{{ $js.Permalink }}"></script>
133138
{{ end }}

layouts/partials/head.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,4 @@
142142
{{ end }}
143143
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
144144
<!-- for parsing suggest markdown to html, since markdownify is not allowed in javascript -->
145-
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
146-
147-
</head>
145+
</head>

static/js/copy-katex.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ document.addEventListener('click', function(event) {
8080
if (fragment.querySelector('.katex-mathml')) {
8181
const texContents = katexReplaceWithTex(fragment).textContent;
8282
navigator.clipboard.writeText(texContents).then(function() {
83-
console.log("Copied");
8483

8584
// Create a temporary element to display the "Copied!" message
8685
const tooltipElement = document.createElement('div');

0 commit comments

Comments
 (0)