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 @@
19 const serviceSecurityAudited = writable(false); 19 const serviceSecurityAudited = writable(false);
20 const serviceCrypto = writable(false); 20 const serviceCrypto = writable(false);
21 const additionalInfo = writable(''); 21 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 }
22 48
23 $: yamlText = yaml.dump([{ 49 $: yamlText = yaml.dump([{
24 name: $serviceName, 50 name: $serviceName,
@@ -34,7 +60,7 @@
34 openSource: $serviceOpenSource, 60 openSource: $serviceOpenSource,
35 securityAudited: $serviceSecurityAudited, 61 securityAudited: $serviceSecurityAudited,
36 acceptsCrypto: $serviceCrypto, 62 acceptsCrypto: $serviceCrypto,
37 }]); 63 }].map(obj => filterEmptyValues(obj)));
38 64
39 $: issueUrl = makeAdditionRequest({ 65 $: issueUrl = makeAdditionRequest({
40 listingCategory: $listingCategory, 66 listingCategory: $listingCategory,
@@ -56,28 +82,16 @@
56 82
57 // Form submission handler 83 // Form submission handler
58 function handleSubmit() { 84 function handleSubmit() {
59 const formData = { 85 window.open(issueUrl, '_blank');
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');
78 } 86 }
79</script> 87</script>
80 88
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
81<p> 95<p>
82 Before completing this form, you must ensure that the service you are adding aligns 96 Before completing this form, you must ensure that the service you are adding aligns
83 with the <a href="/about#creteria">Requirements</a> for Awesome Privacy. 97 with the <a href="/about#creteria">Requirements</a> for Awesome Privacy.
@@ -278,7 +292,10 @@
278 within <a href="github.com/lissy93/awesome-privacy/blob/main/awesome-privacy.yml">awesome-privacy.yml</a> 292 within <a href="github.com/lissy93/awesome-privacy/blob/main/awesome-privacy.yml">awesome-privacy.yml</a>
279 upon approval. 293 upon approval.
280 </p> 294 </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>
282 <p>Your submission will need to be reviewed by a maintainer and the community before it can be merged.</p> 299 <p>Your submission will need to be reviewed by a maintainer and the community before it can be merged.</p>
283</div> 300</div>
284 301