const mongoose = require('mongoose');
const Language = require('../models/Language');
const Contest = require('../models/Contest');
const isValidUTF8 = require('utf-8-validate');
require('../models/Submission');
require('../models/User');
const langs = require('../data/langs.json');
const {stripIndent} = require('common-tags');

mongoose.Promise = global.Promise;

(async () => {
	await mongoose.connect('mongodb://localhost:27017/esolang-battle');

	const contest = await Contest.find({id: '5'});
	const languages = await Language.find({contest})
		.populate({
			path: 'solution',
			populate: {path: 'user'},
		})
		.exec();

	languages.sort(({slug: slugA}, {slug: slugB}) => slugA.localeCompare(slugB));
	for (const language of languages) {
		if (language.solution === null) {
			continue;
		}

		const lang = langs.find(({slug}) => slug === language.slug);
		console.log(stripIndent`
			# [${lang.name}](https://esolang.hakatashi.com/contests/5/submissions/${language.solution._id}) (@${language.solution.user.email.replace(/@.+$/, '')}, ${language.solution.size} bytes)
		`);
		console.log('');
		const isVisible = isValidUTF8(language.solution.code);
		if (isVisible) {
			if (language.solution.size >= 500) {
				console.log([
					'<details>',
					'<summary>コードを見る</summary>',
				].join('\n'));
			}
			console.log('```');
			console.log(language.solution.code.toString());
			console.log('```');
			console.log('');
			if (language.solution.size >= 500) {
				console.log('</details>');
			}
		}
	}

	mongoose.connection.close();
})();

@@ -1244,24 +1244,33 @@
 %3Cdetails%3E',%0A
+%09%09%09%09%09'',%0A
 %09%09%09%09%09'%3Csumma
@@ -1287,24 +1287,33 @@
 /summary%3E',%0A
+%09%09%09%09%09'',%0A
 %09%09%09%09%5D.join('
@@ -1512,16 +1512,37 @@
 ils%3E');%0A
+%09%09%09%09console.log('');%0A
 %09%09%09%7D%0A%09%09%7D

Update writeup-gen.js