Added [[testcases]] that are stored in game dat file, instead of single variables. Split metadata out into a template file for easier modification.

This commit is contained in:
chris062689 2017-06-05 20:46:21 -04:00
parent 672696155d
commit 13e6155ed1
9 changed files with 94 additions and 88 deletions

View File

@ -6,6 +6,7 @@ const logger = require('winston');
const sanitizeHtml = require('sanitize-html');
const toml = require('toml');
const blackfriday = require('./blackfriday.js');
const del = require('delete');
@ -27,9 +28,11 @@ function url(title) {
function gitPull(directory, repository) {
if (fs.existsSync(directory)) {
logger.info(`Fetching latest from Github : ${directory}`);
exec(`cd ${directory} && git pull && cd -`);
logger.info(`git --git-dir=${directory} pull`);
exec(`git --git-dir=${directory} pull`);
} else {
logger.info(`Cloning repository from Github : ${directory}`);
logger.info(`git clone ${repository}`);
exec(`git clone ${repository}`);
}
}
@ -39,17 +42,6 @@ function getDirectories (srcpath) {
.filter(file => fs.lstatSync(path.join(srcpath, file)).isDirectory())
}
String.prototype.trimNewline = function() {
let string = this.toString();
if (string.endsWith('\r\n')) {
return string.slice(0, -2);
} else if (string.endsWith('\r') || string.endsWith('\n')) {
return string.slice(0, -1);
} else {
return string;
}
}
// Fetch game information stored in Github repository.
gitPull(inputDirectoryGame, 'https://github.com/citra-emu/citra-games-wiki.git');
@ -119,10 +111,7 @@ try {
fsextra.copySync(`${inputDirectorySavefilesGame}/${file}`, `${outputDirectorySavefilesGame}/${file.replace('.zip', '.zip')}`);
} else if (path.extname(file) == '.dat') {
// Store the contents of the file in memory for adding it into the markdown later.
savefileMetadataContents.push({
filename: file.replace('.dat', '.zip'),
contents: fs.readFileSync(`${inputDirectorySavefilesGame}/${file}`, 'utf8').trimNewline()
});
savefileMetadataContents.push({ filename: file.replace('.dat', '.zip'), contents: fs.readFileSync(`${inputDirectorySavefilesGame}/${file}`, 'utf8') });
}
});
}
@ -150,14 +139,28 @@ try {
var stats = fs.statSync(`${inputDirectoryGame}/${game}/game.dat`);
let modified = new Date(util.inspect(stats.mtime));
let datContents = fs.readFileSync(`${inputDirectoryGame}/${game}/game.dat`, 'utf8').trimNewline();
let datContents = fs.readFileSync(`${inputDirectoryGame}/${game}/game.dat`, 'utf8');
datContents = `date = "${modified.toISOString()}"\r\n` + datContents;
// Parse testcase information out of the dat to reinject as shortcut values.
try {
var dat = toml.parse(datContents);
if (dat.testcases == null || dat.testcases.length == 0) {
datContents = `compatibility = 99"\r\ntestcase_date = "2000-01-01"\r\n` + datContents;
} else {
let recent = dat.testcases[0];
datContents = `compatibility = ${recent.compatibility}\r\ntestcase_date = "${recent.date}"\r\n` + datContents;
}
} catch (e) {
console.error(`Parsing dat file error on line ${e.line}, column ${e.column}: ${e.message}`);
}
var wikiContents = "";
let wikiPathGame = `${inputDirectoryWiki}/${game}.md`;
if (fs.existsSync(wikiPathGame)) {
wikiContents = fs.readFileSync(wikiPathGame, 'utf8').trimNewline();
wikiContents = fs.readFileSync(wikiPathGame, 'utf8');
} else {
wikiContents = "## No wiki exists yet for this game.";
wikiContents = "No wiki exists yet for this game.";
}
// Fix Blackfriday markdown rendering differences.
@ -167,14 +170,13 @@ try {
// Read all savefiles from array and copy them into the markdown.
savefileMetadataContents.forEach(function(savefile) {
let modified = new Date(util.inspect(stats.mtime));
datContents += `\r\n\r\n[[ savefiles ]]\r\nfilename = "${savefile.filename}"\r\ndate = "${modified.toISOString()}"\r\n${savefile.contents}`;
datContents += `\r\n\r\n[[ savefiles ]]\r\n${savefile.contents}\r\nfilename = "${savefile.filename}"\r\ndate = "${modified.toISOString()}"\r\n`;
});
let output = `+++\r\ndate = "${modified.toISOString()}"\r\n${datContents}\r\n+++\r\n\r\n${wikiContents}\r\n`;
let output = `+++\r\n${datContents}\r\n+++\r\n\r\n${wikiContents}\r\n`;
fs.writeFileSync(`${outputDirectoryMd}/${game}.md`, output);
} catch (ex) {
logger.error(`${game} failed to generate: ${ex}`);
logger.error(ex);
}
});
} catch (ex) {

View File

@ -11,6 +11,7 @@
"rimraf": "^2.6.1",
"sanitize-html": "^1.14.1",
"sync-exec": "^0.6.2",
"toml": "^2.3.2",
"winston": "^2.2.0"
},
"preferGlobal": false,

View File

@ -4,5 +4,6 @@
"2": { "name": "Okay", "color": "#94b242", "description": "Game functions with major graphical or audio glitches, but game is playable from start to finish with workarounds." },
"3": { "name": "Bad", "color": "#f2d624", "description": "Game functions, but with major graphical or audio glitches. Unable to progress in specific areas due to glitches even with workarounds." },
"4": { "name": "Intro/Menu", "color": "red", "description": "Game is completely unplayable due to major graphical or audio glitches. Unable to progress past the Start Screen." },
"5": { "name": "Won't Boot", "color": "#828282", "description": "The game crashes when attempting to startup." }
"5": { "name": "Won't Boot", "color": "#828282", "description": "The game crashes when attempting to startup." },
"99": { "name": "Not Tested", "color": "black", "description": "This game has not yet been tested." }
}

View File

@ -5,6 +5,10 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<meta name="theme-color" content="#FF8E03">
<meta property="og:title" content="{{ if ne .URL "/" }}{{ .Title }} &middot; {{ end }}{{ .Site.Title }}" />
<meta property="og:site_name" content="{{ .Site.Title }}" />
<meta property="og:url" content="{{ .Permalink }}" />
{{ .Render "meta" }}
{{ .Hugo.Generator }}
@ -17,38 +21,7 @@
<link href="{{ .Site.BaseURL }}index.xml" rel="feed" type="application/rss+xml" title="{{ .Site.Title }}" />
{{ end }}
<title>{{ if .IsHome }}Homepage{{ else }}{{ .Title }}{{ end }} | {{ .Site.Title }} | Nintendo 3DS Emulator</title>
<!-- Meta Properties -->
<meta property="og:title" content="{{ if ne .URL "/" }} {{ .Title }} &middot; {{ end }} {{ .Site.Title }}" />
{{ if (eq .Section "game") }}
{{ $rating := index .Site.Data.compatibility ( string .Params.compatibility | default "0" ) }}
<meta property="og:description" content="{{ $rating.name }} - {{ $rating.description }}" />
<meta name="description" content="{{ $rating.name }} - {{ $rating.description }}">
{{ else }}
<meta property="og:description" content="{{ with .Description }}{{ . }}{{ else }}{{ .Summary }}{{ end }}" />
<meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{ .Summary }}{{ end }}">
{{ end }}
   <meta property="og:site_name" content="{{ .Site.Title }}" />
<meta property="og:url" content="{{ .Permalink }}" />
    
{{ if (eq .Section "entry") | or (eq .Section "wiki") | or (eq .Section "game") }}
   <meta property="og:type" content="article" />
{{ if (eq .Section "entry") }}
<meta property="og:image" content="{{ .Site.BaseURL }}images/banners/{{ .Params.Banner | default (print .File.BaseFileName ".png") }}" />
{{ else if (eq .Section "game") }}
<meta property="og:image" content="{{ .Site.BaseURL }}images/game/icons/{{ .File.BaseFileName }}.png" />
{{ end }}
<meta property="og:article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}" />
     {{ range .Params.tags }}
     <meta property="og:article:tag" content="{{ . }}" />
     {{ end }}
    {{ else }}
<meta property="og:type" content="website" />
    {{ end }}
<!-- End Meta Properties -->
<title>{{- if .IsHome }}Homepage{{- else }}{{ .Title }}{{- end }} | {{ .Site.Title }} | Nintendo 3DS Emulator</title>
{{ if eq (getenv "GULP") "true" }}
<link rel="stylesheet" href="/css/main.css"/>

View File

@ -0,0 +1,3 @@
<meta property="og:description" content="{{ with .Description }}{{ . }}{{ else }}{{ .Summary }}{{ end }}" />
<meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{ .Summary }}{{ end }}" />
<meta property="og:type" content="website" />

View File

@ -0,0 +1,8 @@
<meta property="og:description" content="{{ with .Description }}{{ . }}{{ else }}{{ .Summary }}{{ end }}" />
<meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{ .Summary }}{{ end }}" />
<meta property="og:type" content="article" />
<meta property="og:image" content="{{ .Site.BaseURL }}images/banners/{{ .Params.Banner | default (print .File.BaseFileName ".png") }}" />
<meta property="og:article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}" />
{{- range .Params.tags }}
<meta property="og:article:tag" content="{{ . }}" />
{{- end }}

View File

@ -24,15 +24,15 @@
</tr>
</thead>
<tbody>
{{ range .Data.Pages }}
{{ $rating := index .Site.Data.compatibility ( string .Params.compatibility | default "0" ) }}
<tr>
<td style="width: 55px;"><img class="img-responsive game-icon-list" src="{{ .Site.BaseURL }}images/game/icons/{{ default (print .File.BaseFileName ".png") }}" /></td>
<td><a href="{{ .Permalink }}">{{ .Params.title }}</a></td>
<td class="compatibility-row"><div class="square-icon compatibility-{{ replace ($rating.name | urlize) "/" "" }}" style="background-color: {{ $rating.color }}"></div> {{ $rating.name }}</td>
<td>{{ dateFormat "January 2, 2006" .Params.tested_date }}</td>
</tr>
{{ end }}
{{ range .Data.Pages }}
{{- $rating := index .Site.Data.compatibility ( string .Params.compatibility | default "99" ) }}
<tr>
<td style="width: 55px;"><img class="img-responsive game-icon-list" src="{{ .Site.BaseURL }}images/game/icons/{{ default (print .File.BaseFileName ".png") }}" /></td>
<td><a href="{{ .Permalink }}">{{ .Params.title }}</a></td>
<td class="compatibility-row"><div class="square-icon compatibility-{{ replace ($rating.name | urlize) "/" "" }}" style="background-color: {{ $rating.color }}"></div> {{ $rating.name }}</td>
<td>{{ dateFormat "January 2, 2006" .Params.testcase_date }}</td>
</tr>
{{ end }}
</tbody>
</table>
{{ end }}

View File

@ -0,0 +1,10 @@
{{- $rating := index .Site.Data.compatibility ( string .Params.compatibility | default "99" ) }}
<meta property="og:description" content="{{ $rating.name }} - {{ $rating.description }}" />
<meta name="description" content="{{ $rating.name }} - {{ $rating.description }}" />
<meta property="og:type" content="article" />
<meta property="og:image" content="{{ .Site.BaseURL }}images/game/icons/{{ .File.BaseFileName }}.png" />
<meta property="og:article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}" />
{{- range .Params.tags }}
<meta property="og:article:tag" content="{{ . }}" />
{{- end }}

View File

@ -1,7 +1,6 @@
{{ define "main" }}
{{ $BaseURL := .Site.BaseURL }}
{{ $gameName := .File.BaseFileName }}
{{ $rating := index .Site.Data.compatibility ( string .Params.compatibility | default "0" ) }}
<div class="alert alert-info">
<div class="row">
@ -36,6 +35,7 @@
<table class="table table-responsive table-striped table-bordered">
<tbody>
<tr>
{{- $rating := index .Site.Data.compatibility ( string .Params.compatibility | default "99" ) }}
<td style="width: 100px;">Status</td>
<td><b><div class="square-icon" style="background-color: {{ $rating.color }}"></div> {{ $rating.name }}</b><br />{{ $rating.description }}</td>
</tr>
@ -65,32 +65,40 @@
</div>
<p>{{ .Params.Description }}</p>
{{ .Content }}
<!-- Compatibility -->
<div class="row">
<div class="col-md-12">
<h2>Compatibility</h2>
<table class="table table-responsive table-striped">
<thead>
<tr>
<th>Date</th>
<th>Tested By</th>
<th>Citra Version</th>
<th>Rating</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ dateFormat "January 2, 2006" .Params.tested_date }}</td>
<td><a href="https://community.citra-emu.org/u/{{ .Params.tested_by }}/summary">{{ .Params.tested_by }}</a></td>
<td>{{ .Params.tested_version }}</td>
<td><b><div class="square-icon" style="background-color: {{ $rating.color }}"></div> {{ $rating.name }}</b></td>
</tr>
</tbody>
</table>
</div>
</div>
{{ if isset .Params "testcases" }}
{{ $siteCompatibility := .Site.Data.compatibility }}
{{ range .Params.testcases }}
{{ $testcase := . }}
{{ $rating := index $siteCompatibility ( string $testcase.compatibility | default "0" ) }}
<div class="row">
<div class="col-md-12">
<h2>Compatibility</h2>
<table class="table table-responsive table-striped">
<thead>
<tr>
<th>Date</th>
<th>Tested By</th>
<th>Citra Version</th>
<th>Rating</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ dateFormat "January 2, 2006" $testcase.date }}</td>
<td><a href="https://community.citra-emu.org/u/{{ $testcase.owner }}/summary">{{ $testcase.author }}</a></td>
<td>{{ $testcase.version }}</td>
<td><b><div class="square-icon" style="background-color: {{ $rating.color }}"></div> {{ $rating.name }}</b></td>
</tr>
</tbody>
</table>
</div>
</div>
{{ end }}
{{ end }}
{{ if (where (readDir "/static/savefiles") "Name" .File.BaseFileName) }}
<div class="row">