Commit a2f36e1ce7

a2f36e1ce7d8f1f809a59d2aadd85a39dfb07f54

parent: 434d30f5bd

Unsigned

Alicia Sykes <alicia@omg.lol> · 2024-04-01 22:39 UTC

Adds syntax highlighting to YAML snippet, and hides incomplete entries

Layout: unified · split

web/src/components/things/AddNewService.svelte +38 −21
@@ -19,6 +19,32 @@
1919 const serviceSecurityAudited = writable(false);
2020 const serviceCrypto = writable(false);
2121 const additionalInfo = writable('');
22
23 let codeBlock: any;
24 let interactiveActivated = false;
25
26 $: yamlText, updateHighlighting();
27
28 function updateHighlighting() {
29 if (codeBlock) {
30 codeBlock.textContent = yamlText
31 codeBlock.dataset.highlighted && delete codeBlock.dataset.highlighted;
32 if (window && (window as any).hljs) {
33 (window as any).hljs.highlightElement(codeBlock);
34 interactiveActivated = true;
35 }
36 }
37 }
38
39 const filterEmptyValues = (obj: Record<string, any>) => {
40 const filteredObj: Record<string, any> = {};
41 Object.keys(obj).forEach(key => {
42 if (obj[key] || ['name', 'url', 'icon', 'description'].includes(key)) {
43 filteredObj[key] = obj[key];
44 }
45 });
46 return filteredObj;
47 }
2248
2349 $: yamlText = yaml.dump([{
2450 name: $serviceName,
@@ -34,7 +60,7 @@
3460 openSource: $serviceOpenSource,
3561 securityAudited: $serviceSecurityAudited,
3662 acceptsCrypto: $serviceCrypto,
37 }]);
63 }].map(obj => filterEmptyValues(obj)));
3864
3965 $: issueUrl = makeAdditionRequest({
4066 listingCategory: $listingCategory,
@@ -56,28 +82,16 @@
5682
5783 // Form submission handler
5884 function handleSubmit() {
59 const formData = {
60 listingCategory: $listingCategory,
61 serviceName: $serviceName,
62 serviceUrl: $serviceUrl,
63 serviceIcon: $serviceIcon,
64 serviceDescription: $serviceDescription,
65 serviceGithub: $serviceGithub,
66 serviceTosdrId: $serviceTosdrId,
67 serviceOpenSource: $serviceOpenSource,
68 serviceSecurityAudited: $serviceSecurityAudited,
69 serviceCrypto: $serviceCrypto,
70 additionalInfo: $additionalInfo,
71 serviceIosApp: $serviceIosApp,
72 serviceAndroidApp: $serviceAndroidApp,
73 serviceDiscordInvite: $serviceDiscordInvite,
74 serviceSubreddit: $serviceSubreddit,
75 };
76 const issueCreationUrl = makeAdditionRequest(formData, yamlText);
77 window.open(issueCreationUrl, '_blank');
85 window.open(issueUrl, '_blank');
7886 }
7987</script>
8088
89<svelte:head>
90<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/an-old-hope.min.css">
91<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
92<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/yaml.min.js"></script>
93</svelte:head>
94
8195<p>
8296 Before completing this form, you must ensure that the service you are adding aligns
8397 with the <a href="/about#creteria">Requirements</a> for Awesome Privacy.
@@ -278,7 +292,10 @@
278292 within <a href="github.com/lissy93/awesome-privacy/blob/main/awesome-privacy.yml">awesome-privacy.yml</a>
279293 upon approval.
280294 </p>
281 <pre>{@html yamlText}</pre>
295 {#if !interactiveActivated || !codeBlock}
296 <pre><code class="language-yaml">{@html yamlText}</code></pre>
297 {/if}
298 <pre><code bind:this={codeBlock} class="language-yaml"></code></pre>
282299 <p>Your submission will need to be reviewed by a maintainer and the community before it can be merged.</p>
283300</div>
284301