web/src/utils/data-src-delete-n-edit.ts

44 lines · 2324 bytes

 1import { slugify } from '@utils/fetch-data';
 2
 3export const makeRemovalRequest = (categoryName: string, sectionName: string, serviceName: string, yaml?: string) => {
 4  const title = `[REMOVAL] ${serviceName}`;
 5  const under = `**${serviceName}** (source: [${categoryName} ➜ ${sectionName} ➜ ${serviceName}`
 6    + `](https://github.com/Lissy93/awesome-privacy/tree/main#${slugify(sectionName)}))`;
 7  const removalData = `&title=${encodeURIComponent(title)}&removal-data=`
 8    + `${encodeURIComponent(yaml || '')}&service-title=${encodeURIComponent(under)}`;
 9  const issueCreate = 'https://github.com/Lissy93/awesome-privacy/issues/new'
10  const baseOptions = '?assignees=lissy93&labels=Suggested+Removal%2CAwaiting+'
11    + 'Review&projects=&template=removal.yml'
12  return `${issueCreate}${baseOptions}${removalData}`;
13};
14
15export const makeEditRequest = (categoryName: string, sectionName: string, serviceName: string, yaml?: string) => {
16  const title = `[AMENDMENT] ${serviceName}`;
17  const under = `**${serviceName}** (source: [${categoryName} ➜ ${sectionName} ➜ ${serviceName}`
18    + `](https://github.com/Lissy93/awesome-privacy/tree/main#${slugify(sectionName)}))`;
19  const removalData = `&title=${encodeURIComponent(title)}&amendment-data=`
20    + `${encodeURIComponent(yaml || '')}&service-title=${encodeURIComponent(under)}`;
21  const issueCreate = 'https://github.com/Lissy93/awesome-privacy/issues/new'
22  const baseOptions = '?assignees=lissy93&labels=Suggested+Removal%2CAwaiting+'
23    + 'Review&projects=&template=amendment.yml'
24  return `${issueCreate}${baseOptions}${removalData}`;
25};
26
27export const fetchSrcData = async (categoryName: string, sectionName: string, serviceName: string) => {
28  const lineNumberData = await fetch('/api/line-numbers.json')
29    .then((res) => res.json());
30
31  if ( lineNumberData
32    && lineNumberData[categoryName]
33    && lineNumberData[categoryName][sectionName]
34    && lineNumberData[categoryName][sectionName][serviceName]
35  ) {
36    return {
37      lineNumbers: lineNumberData[categoryName][sectionName][serviceName].lineNumbers,
38      yamlContent: lineNumberData[categoryName][sectionName][serviceName].yaml,
39    };
40  } else {
41    console.error('No line number data found for', categoryName, sectionName, serviceName);
42    return { lineNumbers: [], yamlContent: '' };
43  }
44};