Restructed game content.

This commit is contained in:
chris062689 2017-06-02 21:36:17 -04:00
parent 4b484654a6
commit 69e60ef477
5 changed files with 58 additions and 85 deletions

View File

@ -1,3 +1,4 @@
node_modules/ node_modules/
citra.wiki/ citra-games-wiki/
citra-games-wiki.wiki/
*.log *.log

View File

@ -1,36 +1,48 @@
var fs = require('fs'); const fs = require('fs');
var fsextra = require('fs-extra'); const fsextra = require('fs-extra');
var util = require('util'); const path = require('path');
var logger = require('winston'); const util = require('util');
const logger = require('winston');
var sanitizeHtml = require('sanitize-html'); const sanitizeHtml = require('sanitize-html');
var del = require('delete'); const blackfriday = require('./blackfriday.js');
var exec = require('sync-exec');
var inputDirectoryGame = './citra-games-wiki/'; const del = require('delete');
var inputDirectoryWiki = './citra-games-wiki.wiki/'; const exec = require('sync-exec');
var outputDirectoryMd = '../../site/content/game/';
var outputDirectoryBoxart = '../../site/static/images/games/' const inputDirectoryGame = './citra-games-wiki';
const inputDirectoryWiki = './citra-games-wiki.wiki';
const outputDirectoryMd = '../../site/content/game';
const outputDirectoryBoxart = '../../site/static/images/games/boxart';
// The URL // The URL
function url(title) { function url(title) {
return '/wiki/' + title.replace(/\s+/g, '-').toLowerCase(); return '/wiki/' + title.replace(/\s+/g, '-').toLowerCase();
} }
if (fs.existsSync(inputDirectoryGame)) { function gitPull(directory, repository) {
logger.info(`Purging input directory game: ${inputDirectoryGame}`); if (fs.existsSync(directory)) {
del.sync(inputDirectoryGame, {force: true}); logger.info(`Fetching latest from Github : ${directory}`);
exec(`git --git-dir=${directory} pull`);
} else {
logger.info(`Cloning repository from Github : ${directory}`);
exec(`git clone ${repository}`);
}
} }
if (fs.existsSync(inputDirectoryWiki)) { function getDirectories (srcpath) {
logger.info(`Purging input directory wiki: ${inputDirectoryWiki}`); return fs.readdirSync(srcpath)
del.sync(inputDirectoryWiki, {force: true}); .filter(file => fs.lstatSync(path.join(srcpath, file)).isDirectory())
} }
exec('git clone https://github.com/citra-emu/citra-games-wiki.git'); // Fetch game information stored in Github repository.
exec('git clone https://github.com/citra-emu/citra-games-wiki.wiki.git'); // gitPull(inputDirectoryGame, 'https://github.com/citra-emu/citra-games-wiki.git');
// Fetch game articles stored in Github wiki.
// gitPull(inputDirectoryWiki, 'https://github.com/citra-emu/citra-games-wiki.wiki.git');
// Make sure the output directories in Hugo exist.
if (fs.existsSync(outputDirectoryMd) == false) { if (fs.existsSync(outputDirectoryMd) == false) {
logger.info(`Creating missing output directory: ${outputDirectoryMd}`); logger.info(`Creating missing output directory: ${outputDirectoryMd}`);
fs.mkdirSync(outputDirectoryMd); fs.mkdirSync(outputDirectoryMd);
@ -41,71 +53,31 @@ if (fs.existsSync(outputDirectoryBoxart) == false) {
fs.mkdirSync(outputDirectoryBoxart); fs.mkdirSync(outputDirectoryBoxart);
} }
fs.readdir(inputDirectoryGame, function(err, items) { try {
try { // Loop through each game folder.
// Look for all .md files within the wiki directory. getDirectories(inputDirectoryGame).forEach(function(game) {
items.filter(file => file.substr(-4) === '.png').forEach(function(item) { if (game == '.git') { return; }
logger.info(`Copying boxart PNG ${item}`);
fsextra.copySync(`${inputDirectoryGame}${item}`, `${outputDirectoryBoxart}${item}`);
});
items.filter(file => file.substr(-4) === '.dat').forEach(function(item) {
// Generate the title from the filename.
let title = item.replace(/-/g, ' ').slice(0, -3);
var stats = fs.statSync(`${inputDirectoryGame}${item}`);
var modified = new Date(util.inspect(stats.mtime));
// Read the .dat file and the .md file and fuse them. logger.info(`Creating Hugo files for ${game}`);
fs.readFile(`${inputDirectoryGame}${item}`, 'utf8', function (err,data) {
if (err) { logger.error(err); return; }
try { // Copy the boxart for the game.
// Convert various data inside of the markdown language. fsextra.copySync(`${inputDirectoryGame}/${game}/boxart.png`, `${outputDirectoryBoxart}/${game}.png`);
let cleanGameData = data;
let cleanWikiData = fs.readFileSync(`${inputDirectoryWiki}${item.replace('.dat', '.md')}`, 'utf8');
// Blackfriday Markdown Rendering requires a blank line before lists. // Create the markdown file to be displayed in Hugo.
try { let title = game.replace(/-/g, ' ').slice(0, -3);
var lines = cleanWikiData.split(/\r?\n/); var stats = fs.statSync(`${inputDirectoryGame}/${game}/game.dat`);
for(var i = 0; i < lines.length; i++) { var modified = new Date(util.inspect(stats.mtime));
// If it's the start of the file, ignore to prevent an index issue.
if (i > lines.length) { return; }
if (i == 0 || lines[i] == '\n') { continue; }
// Search for the start of a list designated by the * character. let datContents = fs.readFileSync(`${inputDirectoryGame}/${game}/game.dat`, 'utf8');
if (lines[i].startsWith("* ") && lines[i - 1].startsWith("* ") == false) { let wikiContents = fs.readFileSync(`${inputDirectoryWiki}/${game}.md`, 'utf8');
i = i + 1;
lines.splice(i - 1, 0, '');
}
}
cleanData = lines.join('\n');
} catch (ex) {
logger.error(ex);
}
// Replacing tags like [[Common Issues on Windows|Common Issues]] // Fix Blackfriday markdown rendering differences.
cleanWikiData = cleanWikiData.replace(/\[\[(.*)\|(.*)\]\]/g, function(match, p1, p2) { wikiContents = blackfriday.fixLists(wikiContents);
return `[${p1}](${url(p2)})` wikiContents = blackfriday.fixLinks(wikiContents);
});
// Replacing tags like [[Common Issues]] let output = `+++\r\ndate = "${modified.toISOString()}"\r\n${datContents}+++\r\n\r\n${wikiContents}\r\n`;
cleanWikiData = cleanWikiData.replace(/\[\[(.*)\]\]/g, function(match, p1) { fs.writeFileSync(`${outputDirectoryMd}/${game}.md`, output);
return `[${p1}](${url(p1)})` });
}); } catch (ex) {
logger.error(ex);
// Create the new markdown header for Hugo. }
let newFileContents = `+++\r\ndate = "${modified.toISOString()}"\r\n${cleanGameData}+++\r\n\r\n${cleanWikiData}\r\n`;
let itemOutput = item.toLowerCase().replace('.dat', '.md');
fs.writeFile(`${outputDirectoryMd}${itemOutput}`, newFileContents, function(err) {
if (err) return logger.error(err);
logger.info(`Wrote file ${itemOutput} to filesystem.`);
});
} catch (ex) {
logger.error(ex);
}
});
});
} catch (ex) {
logger.error(ex);
}
});

View File

@ -26,7 +26,7 @@
{{ if (eq .Section "entry") | or (eq .Section "wiki") }} {{ if (eq .Section "entry") | or (eq .Section "wiki") }}
<meta property="og:image" content="{{ .Site.BaseURL }}images/banners/{{ .Params.Banner | default (print .File.BaseFileName ".png") }}" /> <meta property="og:image" content="{{ .Site.BaseURL }}images/banners/{{ .Params.Banner | default (print .File.BaseFileName ".png") }}" />
{{ else if (eq .Section "game") }} {{ else if (eq .Section "game") }}
<meta property="og:image" content="{{ .Site.BaseURL }}images/games/{{ .Params.Banner | default (print .File.BaseFileName ".png") }}" /> <meta property="og:image" content="{{ .Site.BaseURL }}images/games/boxart/{{ .Params.Banner | default (print .File.BaseFileName ".png") }}" />
{{ end }} {{ end }}
<meta property="og:article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}" /> <meta property="og:article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}" />
     {{ range .Params.tags }}      {{ range .Params.tags }}

View File

@ -26,7 +26,7 @@
<h1>{{ .Title }}</h1> <h1>{{ .Title }}</h1>
<div class="row"> <div class="row">
<div class="col-md-5"> <div class="col-md-5">
<img class="center-block img-responsive" style="height: 300px;" src="{{ .Site.BaseURL }}images/games/{{ .Params.Banner | default (print .File.BaseFileName ".png") }}" /> <img class="center-block img-responsive" style="height: 300px;" src="{{ .Site.BaseURL }}images/game/boxart/{{ .Params.Banner | default (print .File.BaseFileName ".png") }}" />
</div> </div>
<div class="col-md-7"> <div class="col-md-7">
<table class="table table-striped"> <table class="table table-striped">

View File

@ -26,7 +26,7 @@
      <description>{{ .Summary | html }}</description>       <description>{{ .Summary | html }}</description>
    </item>     </item>
    {{ end }}     {{ end }}
{{ range where .Data.Pages "Section" "games" }} {{ range where .Data.Pages "Section" "game" }}
    <item>     <item>
      <title>{{ .Title }}</title>       <title>{{ .Title }}</title>
      <link>{{ .Permalink }}</link>       <link>{{ .Permalink }}</link>