Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
- This is basically just a copy of Resolve Cafe with a "find & replace".
  • Loading branch information
latenitefilms committed Jun 20, 2023
1 parent a3a8def commit 1fa28f6
Show file tree
Hide file tree
Showing 158 changed files with 3,324 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [latenitefilms]
custom: ["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HQK87KLKY8EVN"]
59 changes: 59 additions & 0 deletions .github/scripts/generate-bug-tracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const axios = require('axios');
const fs = require('fs');
const { GITHUB_TOKEN, REPO_NAME } = process.env;

const [owner, repo] = REPO_NAME.split('/');

const getIssues = async () => {
const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}/issues`, {
headers: {
Authorization: `Bearer ${GITHUB_TOKEN}`
},
params: {
state: "open",
per_page: 100
}
});

return response.data;
};

const generateMarkdown = (issues, path, sortFunc) => {
let content = '';

// sort issues according to provided sort function
issues.sort(sortFunc);

// select top 30
issues = issues.slice(0, 30);

// build the new list
for (const issue of issues) {
const date = new Date(issue.created_at).toLocaleDateString("en-US", { day: 'numeric', month: 'long', year: 'numeric' });
content += `- [${issue.title} (${date})](${issue.html_url}){target="_blank"}\n`;
}

fs.writeFileSync(path, content);
};

const sumReactions = issue => {
let total = 0;
total += issue.reactions['+1'] || 0;
total += issue.reactions['-1'] || 0;
total += issue.reactions['laugh'] || 0;
total += issue.reactions['hooray'] || 0;
total += issue.reactions['confused'] || 0;
total += issue.reactions['heart'] || 0;
total += issue.reactions['rocket'] || 0;
total += issue.reactions['eyes'] || 0;
return total;
}

getIssues().then(issues => {
const issuesFilteredByRecent = issues.filter(issue => issue.labels.length > 0 && !issue.labels.some(label => label.name === "Feature Request"));
const issuesFilteredByLatest = issuesFilteredByRecent.filter(issue => issue.labels.some(label => label.name === "FCPX 10.6.6"));

generateMarkdown(issuesFilteredByRecent, 'docs/_includes/bugtracker-recent.md', (a, b) => new Date(b.created_at) - new Date(a.created_at));
// generateMarkdown(issuesFilteredByLatest, 'docs/_includes/bugtracker-latest.md', (a, b) => new Date(b.created_at) - new Date(a.created_at));
generateMarkdown(issuesFilteredByRecent, 'docs/_includes/bugtracker-reactions.md', (a, b) => sumReactions(b) - sumReactions(a));
});
61 changes: 61 additions & 0 deletions .github/scripts/generate-faq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const fs = require('fs');
const path = require('path');

const pageName = 'faq';
const directoryPath = path.join(process.env.GITHUB_WORKSPACE, `docs/_includes/${pageName}`);
const outputFile = path.join(process.env.GITHUB_WORKSPACE, `docs/_includes/generated-${pageName}.md`);

try {
fs.readdir(directoryPath, async function (err, files) {
if (err) {
throw new Error('Unable to scan directory: ' + err);
}

// filter out non-markdown files and create an array of objects containing file info
const fileInfo = files.filter(file => path.extname(file) === '.md').map(file => {
const content = fs.readFileSync(path.join(directoryPath, file), 'utf-8');
const firstLine = content.split('\n')[0].replace('### ', ''); // remove '### ' prefix
return { file, firstLine };
});

// sort the fileInfo array based on the first line
fileInfo.sort((a, b) => a.firstLine.localeCompare(b.firstLine));

let fileContent = '';
let lastInitial = '';

fileInfo.forEach(function ({ file, firstLine }) {
// Removing file extension for include command
const fileNameWithoutExtension = path.parse(file).name;

// Extract first character of the file name
const currentInitial = firstLine.charAt(0).toUpperCase();

// If current initial is different from last initial, then add a new section
if (currentInitial !== lastInitial) {
// Don't add '---' for the first section
if (lastInitial !== '') {
fileContent += '\n---\n\n';
}

fileContent += `## ${currentInitial}\n\n`;
lastInitial = currentInitial;
}

fileContent += `{{ include "${pageName}/${fileNameWithoutExtension}" }}\n\n`;
});

// Remove the last extra line and '---'
fileContent = fileContent.slice(0, -2);

// Write to the output file
try {
fs.writeFileSync(outputFile, fileContent);
console.log(`Successfully written to ${outputFile}`);
} catch (err) {
throw new Error('Unable to write to file: ' + err);
}
});
} catch (err) {
console.error(err);
}
68 changes: 68 additions & 0 deletions .github/scripts/generate-latest-news.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const fs = require('fs');
const path = require('path');

const directoryPath = path.join(process.env.GITHUB_WORKSPACE, 'docs/_includes/news');
const sponsorsPath = path.join(process.env.GITHUB_WORKSPACE, 'docs/_includes/sponsors');
const outputFile = path.join(process.env.GITHUB_WORKSPACE, 'docs/_includes/generated-latest-news.md');

try {
// Read the sponsor files
const sponsorFiles = fs.readdirSync(sponsorsPath).filter(file => path.extname(file) === '.md').sort();

fs.readdir(directoryPath, function (err, files) {
if (err) {
throw new Error('Unable to scan directory: ' + err);
}

// Filter markdown files and sort in descending order
const mdFiles = files
.filter(file => path.extname(file) === '.md')
.sort()
.reverse();

let outputContent = '';
let currentYear = '';
let currentMonth = '';
const monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
let sponsorIndex = 0;

mdFiles.forEach((file, index) => {
const date = file.replace('.md', '');
const year = date.slice(0, 4);
const month = monthNames[parseInt(date.slice(4, 6), 10) - 1];

// Update the year and month headers if needed
if (year !== currentYear) {
outputContent += `# ${year}\n`;
currentYear = year;
}
if (month !== currentMonth) {
outputContent += `## ${month}\n\n`;
currentMonth = month;
}

outputContent += `{{ include "news/${date}" }}\n\n---\n\n{{ include "discuss-todays-news" }}\n\n---\n\n`;

// Add sponsor
if (sponsorFiles.length > 0) {
// Always show sponsor-01.md as the first sponsor item, but only once.
if (index === 0) {
outputContent += `{{ include "sponsors/${sponsorFiles[0]}" }}\n\n---\n\n`;
} else {
sponsorIndex = (sponsorIndex % (sponsorFiles.length - 1)) + 1;
outputContent += `{{ include "sponsors/${sponsorFiles[sponsorIndex]}" }}\n\n---\n\n`;
}
}
});

// Write to the output file
try {
fs.writeFileSync(outputFile, outputContent);
console.log(`Successfully written to ${outputFile}`);
} catch (err) {
throw new Error('Unable to write to file: ' + err);
}
});
} catch (err) {
console.error(err);
}
89 changes: 89 additions & 0 deletions .github/scripts/generate-markdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const fs = require('fs');
const path = require('path');
const { PAGE_NAME } = process.env;

const directoryPath = path.join(process.env.GITHUB_WORKSPACE, `docs/_includes/${PAGE_NAME}`);
const outputFile = path.join(process.env.GITHUB_WORKSPACE, `docs/_includes/generated-${PAGE_NAME}.md`);

try {
const files = fs.readdirSync(directoryPath);
if (!files.length) {
console.log(`No files found in the directory ${directoryPath}`);
}

let fileContent = '';
let lastInitial = '';

// Map files to an array of objects containing file name and first line
let fileList = [];
for (const file of files) {
// Ignore if not a markdown file
if(path.extname(file) !== '.md') {
console.log(`Ignoring non-markdown file: ${file}`);
continue;
}

const filePath = path.join(directoryPath, file);
let fileContent = fs.readFileSync(filePath, 'utf-8');

// Check if the first line is an include command
const includeCommandRegex = /^\s*\{\{\s*include\s*"([^"]+)"\s*\}\}\s*$/;
const match = fileContent.match(includeCommandRegex);

if (match) {
// If so, read the included file instead
const includedFilePath = path.join(process.env.GITHUB_WORKSPACE, `docs/_includes/${match[1]}.md`);
if (fs.existsSync(includedFilePath)) {
fileContent = fs.readFileSync(includedFilePath, 'utf-8');
} else {
console.error(`The included file ${includedFilePath} doesn't exist.`);
continue;
}
}

const firstLineWithoutHashes = fileContent.split('\n')[0].replace(/^[#]*\s*/, ''); // remove hashes and leading space
fileList.push({file, firstLine: firstLineWithoutHashes});
}

// Sort the array based on the first line of each file
fileList.sort((a, b) => a.firstLine.localeCompare(b.firstLine));

for (const {file, firstLine} of fileList) {
const fileNameWithoutExtension = path.parse(file).name;

// Extract first character of the first line
const currentInitial = firstLine.charAt(0).toUpperCase();

// If current initial is different from last initial, then add a new section
if (currentInitial !== lastInitial) {
// Add '---' for the new section except the first
if (lastInitial !== '') {
fileContent += '\n---\n\n';
}

fileContent += `## ${currentInitial}\n\n`;
lastInitial = currentInitial;
}

fileContent += `{{ include "${PAGE_NAME}/${fileNameWithoutExtension}" }}\n`;

// Add '---' separator if the next file is not of the same initial
const nextFile = fileList[fileList.findIndex(f => f.file === file) + 1];
if (nextFile && currentInitial !== nextFile.firstLine.charAt(0).toUpperCase()) {
fileContent += '\n---\n\n';
}
}

// Remove the last extra lines
fileContent = fileContent.replace(/\n$/, '');

// Write to the output file
try {
fs.writeFileSync(outputFile, fileContent);
console.log(`Successfully written to ${outputFile}`);
} catch (err) {
throw new Error('Unable to write to file: ' + err);
}
} catch (err) {
console.error(err);
}
Loading

0 comments on commit 1fa28f6

Please sign in to comment.