2019-04-29 02:11:57 +02:00
|
|
|
<template>
|
2019-07-09 10:01:08 +02:00
|
|
|
<div class="iroscrza" :class="{ shadow: $store.state.device.useShadow, round: $store.state.device.roundedCorners, center: page.alignCenter, serif: page.font === 'serif' }">
|
2019-07-06 23:56:13 +02:00
|
|
|
<header v-if="showTitle">
|
2019-04-29 02:11:57 +02:00
|
|
|
<div class="title">{{ page.title }}</div>
|
|
|
|
</header>
|
|
|
|
|
|
|
|
<div v-if="script">
|
|
|
|
<x-block v-for="child in page.content" :value="child" @input="v => updateBlock(v)" :page="page" :script="script" :key="child.id" :h="2"/>
|
|
|
|
</div>
|
|
|
|
|
2019-07-06 23:56:13 +02:00
|
|
|
<footer v-if="showFooter">
|
2019-04-29 02:11:57 +02:00
|
|
|
<small>@{{ page.user.username }}</small>
|
2019-07-06 23:56:13 +02:00
|
|
|
<template v-if="$store.getters.isSignedIn && $store.state.i.id === page.userId">
|
|
|
|
<router-link :to="`/i/pages/edit/${page.id}`">{{ $t('edit-this-page') }}</router-link>
|
|
|
|
<a v-if="$store.state.i.pinnedPageId === page.id" @click="pin(false)">{{ $t('unpin-this-page') }}</a>
|
|
|
|
<a v-else @click="pin(true)">{{ $t('pin-this-page') }}</a>
|
|
|
|
</template>
|
2019-05-01 13:48:56 +02:00
|
|
|
<router-link :to="`./${page.name}/view-source`">{{ $t('view-source') }}</router-link>
|
2019-05-17 12:56:47 +02:00
|
|
|
<div class="like">
|
|
|
|
<button @click="unlike()" v-if="page.isLiked" :title="$t('unlike')"><fa :icon="faHeartS"/></button>
|
|
|
|
<button @click="like()" v-else :title="$t('like')"><fa :icon="faHeart"/></button>
|
|
|
|
<span class="count" v-if="page.likedCount > 0">{{ page.likedCount }}</span>
|
|
|
|
</div>
|
2019-04-29 02:11:57 +02:00
|
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
|
|
|
import i18n from '../../../../i18n';
|
2019-05-17 12:56:47 +02:00
|
|
|
import { faHeart as faHeartS } from '@fortawesome/free-solid-svg-icons';
|
2019-07-06 23:56:13 +02:00
|
|
|
import { faHeart } from '@fortawesome/free-regular-svg-icons';
|
2019-04-29 02:11:57 +02:00
|
|
|
import XBlock from './page.block.vue';
|
2019-05-01 11:33:11 +02:00
|
|
|
import { ASEvaluator } from '../../../../../../misc/aiscript/evaluator';
|
2019-04-29 02:11:57 +02:00
|
|
|
import { collectPageVars } from '../../../scripts/collect-page-vars';
|
2019-04-30 05:15:41 +02:00
|
|
|
import { url } from '../../../../config';
|
2019-04-29 02:11:57 +02:00
|
|
|
|
|
|
|
class Script {
|
2019-05-01 11:33:11 +02:00
|
|
|
public aiScript: ASEvaluator;
|
2019-05-01 08:17:24 +02:00
|
|
|
private onError: any;
|
2019-05-01 07:54:34 +02:00
|
|
|
public vars: Record<string, any>;
|
2019-07-06 11:14:50 +02:00
|
|
|
public page: Record<string, any>;
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2019-07-06 11:14:50 +02:00
|
|
|
constructor(page, aiScript, onError) {
|
|
|
|
this.page = page;
|
2019-04-29 02:11:57 +02:00
|
|
|
this.aiScript = aiScript;
|
2019-05-01 08:17:24 +02:00
|
|
|
this.onError = onError;
|
|
|
|
this.eval();
|
2019-04-29 02:11:57 +02:00
|
|
|
}
|
|
|
|
|
2019-05-01 08:17:24 +02:00
|
|
|
public eval() {
|
|
|
|
try {
|
|
|
|
this.vars = this.aiScript.evaluateVars();
|
|
|
|
} catch (e) {
|
|
|
|
this.onError(e);
|
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public interpolate(str: string) {
|
2019-04-29 23:40:02 +02:00
|
|
|
if (str == null) return null;
|
2019-05-05 02:27:55 +02:00
|
|
|
return str.replace(/{(.+?)}/g, match => {
|
2019-05-01 07:54:34 +02:00
|
|
|
const v = this.vars[match.slice(1, -1).trim()];
|
2019-04-29 04:08:35 +02:00
|
|
|
return v == null ? 'NULL' : v.toString();
|
|
|
|
});
|
2019-04-29 02:11:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
i18n: i18n('pages'),
|
|
|
|
|
|
|
|
components: {
|
|
|
|
XBlock
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
2019-07-06 23:56:13 +02:00
|
|
|
page: {
|
|
|
|
type: Object,
|
2019-04-29 02:11:57 +02:00
|
|
|
required: true
|
|
|
|
},
|
2019-07-06 23:56:13 +02:00
|
|
|
showTitle: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
showFooter: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
2019-04-29 02:11:57 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
script: null,
|
2019-05-17 12:56:47 +02:00
|
|
|
faHeartS, faHeart
|
2019-04-29 02:11:57 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
2019-07-06 23:56:13 +02:00
|
|
|
const pageVars = this.getPageVars();
|
|
|
|
this.script = new Script(this.page, new ASEvaluator(this.page.variables, pageVars, {
|
|
|
|
randomSeed: Math.random(),
|
|
|
|
user: this.page.user,
|
|
|
|
visitor: this.$store.state.i,
|
|
|
|
page: this.page,
|
|
|
|
url: url
|
|
|
|
}), e => {
|
|
|
|
console.dir(e);
|
|
|
|
});
|
2019-04-29 02:11:57 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
getPageVars() {
|
|
|
|
return collectPageVars(this.page.content);
|
|
|
|
},
|
2019-05-17 12:56:47 +02:00
|
|
|
|
|
|
|
like() {
|
|
|
|
this.$root.api('pages/like', {
|
|
|
|
pageId: this.page.id,
|
|
|
|
}).then(() => {
|
|
|
|
this.page.isLiked = true;
|
|
|
|
this.page.likedCount++;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
unlike() {
|
|
|
|
this.$root.api('pages/unlike', {
|
|
|
|
pageId: this.page.id,
|
|
|
|
}).then(() => {
|
|
|
|
this.page.isLiked = false;
|
|
|
|
this.page.likedCount--;
|
|
|
|
});
|
2019-07-06 23:56:13 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
pin(pin) {
|
|
|
|
this.$root.api('i/update', {
|
|
|
|
pinnedPageId: pin ? this.page.id : null,
|
|
|
|
}).then(() => {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'success',
|
|
|
|
splash: true
|
|
|
|
});
|
|
|
|
});
|
2019-05-17 12:56:47 +02:00
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
.iroscrza
|
|
|
|
overflow hidden
|
|
|
|
background var(--face)
|
2019-07-09 10:01:08 +02:00
|
|
|
|
|
|
|
&.serif
|
|
|
|
> div
|
|
|
|
font-family serif
|
2019-04-29 02:11:57 +02:00
|
|
|
|
|
|
|
&.center
|
|
|
|
text-align center
|
|
|
|
|
|
|
|
&.round
|
|
|
|
border-radius 6px
|
|
|
|
|
|
|
|
&.shadow
|
|
|
|
box-shadow 0 3px 8px rgba(0, 0, 0, 0.2)
|
|
|
|
|
|
|
|
> header
|
|
|
|
> .title
|
|
|
|
z-index 1
|
|
|
|
margin 0
|
2019-05-24 12:19:43 +02:00
|
|
|
padding 16px 32px
|
|
|
|
font-size 20px
|
2019-04-29 02:11:57 +02:00
|
|
|
font-weight bold
|
|
|
|
color var(--text)
|
|
|
|
box-shadow 0 var(--lineWidth) rgba(#000, 0.07)
|
|
|
|
|
|
|
|
@media (max-width 600px)
|
|
|
|
padding 16px 32px
|
|
|
|
font-size 20px
|
|
|
|
|
2019-05-25 01:49:58 +02:00
|
|
|
@media (max-width 400px)
|
|
|
|
padding 10px 20px
|
|
|
|
font-size 16px
|
|
|
|
|
2019-04-29 02:11:57 +02:00
|
|
|
> div
|
|
|
|
color var(--text)
|
2019-05-24 12:19:43 +02:00
|
|
|
padding 24px 32px
|
|
|
|
font-size 16px
|
2019-04-29 02:11:57 +02:00
|
|
|
|
|
|
|
@media (max-width 600px)
|
|
|
|
padding 24px 32px
|
|
|
|
font-size 16px
|
|
|
|
|
2019-05-25 01:49:58 +02:00
|
|
|
@media (max-width 400px)
|
|
|
|
padding 20px 20px
|
|
|
|
font-size 15px
|
|
|
|
|
2019-04-29 02:11:57 +02:00
|
|
|
> footer
|
|
|
|
color var(--text)
|
2019-05-24 12:19:43 +02:00
|
|
|
padding 0 32px 28px 32px
|
2019-04-29 02:11:57 +02:00
|
|
|
|
|
|
|
@media (max-width 600px)
|
|
|
|
padding 0 32px 28px 32px
|
|
|
|
|
2019-05-25 01:49:58 +02:00
|
|
|
@media (max-width 400px)
|
|
|
|
padding 0 20px 20px 20px
|
|
|
|
font-size 14px
|
|
|
|
|
2019-04-29 02:11:57 +02:00
|
|
|
> small
|
|
|
|
display block
|
|
|
|
opacity 0.5
|
|
|
|
|
2019-05-01 13:48:56 +02:00
|
|
|
> a
|
2019-05-25 01:49:58 +02:00
|
|
|
font-size 90%
|
2019-05-01 13:48:56 +02:00
|
|
|
|
|
|
|
> a + a
|
|
|
|
margin-left 8px
|
|
|
|
|
2019-05-17 12:56:47 +02:00
|
|
|
> .like
|
|
|
|
margin-top 16px
|
|
|
|
|
2019-04-29 02:11:57 +02:00
|
|
|
</style>
|