mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-09 20:12:41 +00:00
Merge branch 'master' into License_Snippets_Redux
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const Markdown = require('../../../../shared/naturalcrit/markdown.js');
|
||||
import Markdown from '../../../../shared/naturalcrit/markdown.js';
|
||||
|
||||
module.exports = {
|
||||
createFooterFunc : function(headerSize=1){
|
||||
|
||||
85
themes/V3/Blank/snippets/index.gen.js
Normal file
85
themes/V3/Blank/snippets/index.gen.js
Normal file
@@ -0,0 +1,85 @@
|
||||
const dedent = require('dedent-tabs').default;
|
||||
|
||||
module.exports = ()=>{
|
||||
return dedent`
|
||||
{{index,wide,columns:5;
|
||||
##### Index
|
||||
- Ankhesh-Bort
|
||||
- city map, 7
|
||||
- city watch, 12
|
||||
- guilds, 19
|
||||
- Cheese
|
||||
- types of cheese, 8
|
||||
- cheese-related magic, 14
|
||||
- cheese-related quests, 26-27
|
||||
- Death
|
||||
- appearance, 10
|
||||
- personality, 13
|
||||
- hobbies, 23
|
||||
- Elves
|
||||
- types of elves, 15
|
||||
- elvish magic, 24
|
||||
- elvish curses, 28
|
||||
- Footnotes
|
||||
- types of footnotes, 16-17
|
||||
- footnote rules, 20-21
|
||||
- footnote humor, 29-30
|
||||
- Gods
|
||||
- types of gods, 12
|
||||
- godly interventions, 25
|
||||
- godly conflicts, 31
|
||||
- Heroes
|
||||
- class features, 11-12
|
||||
- heroic deeds, 26-27
|
||||
- Inns
|
||||
- types of inns, 9
|
||||
- inn amenities, 18
|
||||
- Jokes
|
||||
- types of jokes, 11-12
|
||||
- joke delivery, 25
|
||||
- Knives
|
||||
- types of knives, 16-17
|
||||
- knife skills, 22-23
|
||||
- knife fights, 28-29
|
||||
- Luggage
|
||||
- appearance, 10
|
||||
- personality, 13
|
||||
- abilities, 23
|
||||
- Magic
|
||||
- types of magic, 15
|
||||
- magic rules, 24
|
||||
- magic mishaps, 28
|
||||
- Socks
|
||||
- types of socks, 9
|
||||
- sock-related magic (yes, really), 15
|
||||
- sock-related quests (no, really), 26
|
||||
- Trolls
|
||||
- appearance and biology, 11
|
||||
- culture and language, 18
|
||||
- troll rights and activism, 31
|
||||
- Unknown University
|
||||
- history and architecture, 12
|
||||
- faculty and staff, 20
|
||||
- courses and exams, 33
|
||||
- Vampires
|
||||
- types and origins, 13
|
||||
- vampiric powers and weaknesses, 21
|
||||
- vampiric etiquette and politics, 34
|
||||
- Witches
|
||||
- types and traditions, 14
|
||||
- witchcraft and headology, 22
|
||||
- witch trials and tribulations, 35
|
||||
- Xylophones
|
||||
- musical instruments or weapons?, 15
|
||||
- xylophone-related magic and lore, 23
|
||||
- xylophone-related quests and puzzles, 36
|
||||
- Yetis
|
||||
- appearance and behavior, 16
|
||||
- yeti philosophy and religion, 24
|
||||
- yeti encounters and stories, 37
|
||||
- Zombies
|
||||
- types and causes, 17
|
||||
- zombie rights and duties, 25
|
||||
- zombie survival and prevention, 38
|
||||
}}`;
|
||||
};
|
||||
78
themes/V3/Blank/snippets/tableOfContents.gen.js
Normal file
78
themes/V3/Blank/snippets/tableOfContents.gen.js
Normal file
@@ -0,0 +1,78 @@
|
||||
const dedent = require('dedent-tabs').default;
|
||||
|
||||
// Map each actual page to its footer label, accounting for skips or numbering resets
|
||||
const mapPages = (pages)=>{
|
||||
let actualPage = 0;
|
||||
let mappedPage = 0; // Number displayed in footer
|
||||
const pageMap = [];
|
||||
|
||||
pages.forEach((page)=>{
|
||||
actualPage++;
|
||||
const doSkip = page.querySelector('.skipCounting');
|
||||
const doReset = page.querySelector('.resetCounting');
|
||||
|
||||
if(doReset)
|
||||
mappedPage = 1;
|
||||
if(!doSkip && !doReset)
|
||||
mappedPage++;
|
||||
|
||||
pageMap[actualPage] = {
|
||||
mappedPage : mappedPage,
|
||||
showPage : !doSkip
|
||||
};
|
||||
});
|
||||
return pageMap;
|
||||
};
|
||||
|
||||
const getMarkdown = (headings, pageMap)=>{
|
||||
const levelPad = ['- ###', ' - ####', ' -', ' -', ' -', ' -'];
|
||||
|
||||
const allMarkdown = [];
|
||||
const depthChain = [0];
|
||||
|
||||
headings.forEach((heading)=>{
|
||||
const page = parseInt(heading.closest('.page').id?.replace(/^p/, ''));
|
||||
const mappedPage = pageMap[page].mappedPage;
|
||||
const showPage = pageMap[page].showPage;
|
||||
const title = heading.textContent.trim();
|
||||
const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC');
|
||||
const depth = parseInt(heading.tagName.substring(1));
|
||||
|
||||
if(!title || !showPage || ToCExclude == 'exclude')
|
||||
return;
|
||||
|
||||
//If different header depth than last, remove indents until nearest higher-level header, then indent once
|
||||
if(depth !== depthChain[depthChain.length -1]) {
|
||||
while (depth <= depthChain[depthChain.length - 1]) {
|
||||
depthChain.pop();
|
||||
}
|
||||
depthChain.push(depth);
|
||||
}
|
||||
|
||||
const markdown = `${levelPad[depthChain.length - 2]} [{{ ${title}}}{{ ${mappedPage}}}](#p${page})`;
|
||||
allMarkdown.push(markdown);
|
||||
});
|
||||
return allMarkdown.join('\n');
|
||||
};
|
||||
|
||||
const getTOC = ()=>{
|
||||
const iframe = document.getElementById('BrewRenderer');
|
||||
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
|
||||
const headings = iframeDocument.querySelectorAll('h1, h2, h3, h4, h5, h6');
|
||||
const pages = iframeDocument.querySelectorAll('.page');
|
||||
|
||||
const pageMap = mapPages(pages);
|
||||
return getMarkdown(headings, pageMap);
|
||||
};
|
||||
|
||||
module.exports = function(props){
|
||||
const TOC = getTOC();
|
||||
|
||||
return dedent`
|
||||
{{toc,wide
|
||||
# Contents
|
||||
|
||||
${TOC}
|
||||
}}
|
||||
\n`;
|
||||
};
|
||||
Reference in New Issue
Block a user