Printing improvements

This commit is contained in:
Heerko 2021-07-16 23:03:53 +02:00
parent d6ce199bb9
commit 071a88dc47
4 changed files with 35 additions and 38 deletions

View file

@ -10,7 +10,7 @@
</span> </span>
</div> </div>
<div style="float: none"><div style="page-break-after: always"></div></div> <!-- <div style="float: none"><div style="page-break-after: always"></div></div> -->
</div> </div>
</template> </template>
@ -23,15 +23,13 @@ export default {
Message, Message,
}, },
data() { data() {
return { return {};
}
}, },
props: ["topic", "show_message_data"], props: ["topic", "show_message_data"],
computed: { computed: {
messagesToShow() { messagesToShow() {
return this.topic.messages return this.topic.messages.filter((m) => !m.responseTo);
.filter(m => !m.responseTo) },
}
}, },
}; };
</script> </script>

View file

@ -1,11 +1,8 @@
<template> <template>
<section> <section>
<h1 class="title">{{ title }}</h1> <h1 class="title">{{ title }}</h1>
<ul> <ul class="index">
<li <li v-for="topic in sortedTopics" :key="topic.title">
v-for="topic in sortedTopics"
:key="topic.title"
>
<router-link <router-link
:to="`#${toValidID(topic.title)}`" :to="`#${toValidID(topic.title)}`"
@click.stop="goTo(`#${toValidID(topic.title)}`)" @click.stop="goTo(`#${toValidID(topic.title)}`)"
@ -14,7 +11,7 @@
</router-link> </router-link>
</li> </li>
</ul> </ul>
<div style="float: none"><div style="page-break-after: always"></div></div> <!-- <div style="float: none"><div style="page-break-after: always"></div></div> -->
<Chapter <Chapter
v-for="topic in sortedTopics" v-for="topic in sortedTopics"
:key="topic.title" :key="topic.title"
@ -40,24 +37,22 @@ export default {
...mapState(["currentStream", "streams"]), ...mapState(["currentStream", "streams"]),
...mapGetters(["sortedTopics"]), ...mapGetters(["sortedTopics"]),
title() { title() {
return this.streams.find(s => s.name == this.currentStream) ? return this.streams.find((s) => s.name == this.currentStream)
this.currentStream.replace("pub-", "") : 'Stream does not exist.' ? this.currentStream.replace("pub-", "")
} : "Stream does not exist.";
},
}, },
methods: { methods: {
toValidID(string) { return ( toValidID(string) {
encodeURIComponent('ch-' + string) return encodeURIComponent("ch-" + string)
.toLowerCase() .toLowerCase()
.replace(/\.|%[0-9a-z]{2}/gi, '') .replace(/\.|%[0-9a-z]{2}/gi, "");
)}, },
goTo(id) { goTo(id) {
document document.querySelector(`.${this.currentStream} ${id}`).scrollIntoView({
.querySelector(`.${this.currentStream} ${id}`) behavior: "smooth",
.scrollIntoView({ });
behavior: 'smooth' },
})
}
}, },
}; };
</script> </script>
@ -68,4 +63,8 @@ export default {
/* display: none; */ /* display: none; */
} }
} }
.index {
page-break-after: always;
}
</style> </style>

View file

@ -9,6 +9,8 @@ import { stripHtml } from "string-strip-html"
var EmojiConvertor = require('emoji-js'); var EmojiConvertor = require('emoji-js');
var emojiConv = new EmojiConvertor(); var emojiConv = new EmojiConvertor();
// let emojis = require('emojis');
let toCSS = (message, currentStream) => { let toCSS = (message, currentStream) => {
let content = stripHtml(message.content).result; let content = stripHtml(message.content).result;
let className = "", let className = "",
@ -25,14 +27,16 @@ let toCSS = (message, currentStream) => {
let regex = /\s?(?<selector>.+)\s*\n?{\n?(?<props>(.*;\n?)+)}/gm let regex = /\s?(?<selector>.+)\s*\n?{\n?(?<props>(.*;\n?)+)}/gm
let results = content.matchAll(regex); let results = content.matchAll(regex);
results = Array.from(results); results = Array.from(results);
if (is_font) { // font if (is_font) { // font
let re_path = /\/user_uploads(\/.*?\.(?:ttf|otf|woff))/gm; let re_path = /\/user_uploads(\/.*?\.(?:ttf|otf|woff))/gm;
// content = message.content.matchAll(re_path);
content = re_path.exec(message.content)[1]; content = re_path.exec(message.content)[1];
// console.log(message.content, content)
return { className: '', emoji_code: '', rules: [], parentClassName: '', id: id, content: font(content), type: type } return { className: '', emoji_code: '', rules: [], parentClassName: '', id: id, content: font(content), type: type }
} else if (is_codeblock) {
return { className: '', emoji_code: '', rules: [], parentClassName: '', id: id, content: content, type: type }
} else if (results.length > 0) { // rule and raw } else if (results.length > 0) { // rule and raw
className = emojiConv.replace_colons(results[0]['groups']['selector']); className = emojiConv.replace_colons(results[0]['groups']['selector']);
if (emoji.methods.containsEmoji(className)) { if (emoji.methods.containsEmoji(className)) {
emoji_code = emoji.methods.toEmojiCode(className); emoji_code = emoji.methods.toEmojiCode(className);
} }
@ -40,6 +44,7 @@ let toCSS = (message, currentStream) => {
rules = rules.filter((rule) => validateRule(rule)) rules = rules.filter((rule) => validateRule(rule))
return { className, emoji_code, rules, parentClassName, id, content, type }; return { className, emoji_code, rules, parentClassName, id, content, type };
} }
console.log("rejected rule", message)
return null; return null;
} }

View file

@ -134,6 +134,7 @@ export default {
width: 100%; width: 100%;
display: flex; display: flex;
} }
.controls-pane { .controls-pane {
background-color: #aaa; background-color: #aaa;
} }
@ -174,20 +175,14 @@ export default {
display: block !important; display: block !important;
} }
.print .body { .body {
page-break-after: always; page-break-after: always;
/* border-bottom: 3px dotted green; */
} }
.body img { .body img {
max-width: 100%; max-width: 100%;
} }
/* .print .body:first-of-type {
page-break-after: always;
border-bottom: 3px dotted yellow;
} */
.float-btn { .float-btn {
position: fixed; position: fixed;
z-index: 1000; z-index: 1000;