Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Deep in the code

Javier Villanueva jahvi

👨‍💻
Deep in the code
View GitHub Profile
View Home.vue
<script>
export default {
async asyncData ({ store, route }) {
// ...
// Prefetch CMS data on the server
await store.dispatch('cmsBlock/list', {
filterValues: ['home_banner'] // Array of CMS blocks identifiers on the page
})
}
}
View LeftBanner.vue
<template>
<div
class="offer-container col-xs-12 col-sm-6 pb15"
v-if="data"
>
<router-link :to="localizedRoute(link)">
<div
class="offer"
v-lazy:background-image="image"
>
View NewPromotedOffers.vue
<template>
<section v-if="!singleBanner" class="offers container my30 px15 cl-black">
<div class="row">
<left-banner :identifier="'home_banner'" />
<!-- ... -->
</div>
</section>
</template>
View parser.js
import { parse } from 'node-html-parser';
const root = parse('<ul id="list"><li>Hello World</li></ul>');
console.log(root.firstChild.structure);
// ul#list
// li
// #text
console.log(root.querySelector('#list'));
View PromotedOffers.vue
<template>
<section v-if="!singleBanner" class="offers container my30 px15 cl-black">
<div class="row">
<cms-block :identifier="'home_banner'" />
<!-- ... -->
</div>
</section>
</template>
View server-express.js
const express = require('express');
const { middleware } = require('@magento/upward-js');
async function serve() {
const app = express();
const port = 8000;
app.get('/', (req, res) => res.send('Hello from Express!'));
const upwardMiddleware = await middleware(`${__dirname}/upward.yml`);
View getPokemonDetail.graphql
query($pokemonName: String) {
pokemon(name: $pokemonName) {
name
image
types
weight {
minimum
maximum
}
height {
View upward-ssr-styled.yml
status: response.status # [Go to 1]
headers: response.headers # [Go to 1]
body: response.body # [Go to 1]
# 1
response:
when:
- matches: request.url.pathname
pattern: '^/pokemon/graphql'
use: pokemonGQL # [Go to 2]
View pokemon-ssr.mst
<img src="{{pokemonData.image}}" /><br/>
<strong>Name:</strong> {{pokemonData.name}}<br/>
<strong>Type:</strong>
{{#pokemonData.types}}
{{.}}
{{/pokemonData.types}}
<br/>
<strong>Height:</strong>
{{pokemonData.height.minimum}} - {{pokemonData.height.maximum}}<br/>
<strong>Weight:</strong>
View upward-ssr.yml
status: response.status # [Go to 1]
headers: response.headers # [Go to 1]
body: response.body # [Go to 1]
# 1
response:
when:
- matches: request.url.pathname
pattern: '^/pokemon/graphql'
use: pokemonGQL # [Go to 2]
You can’t perform that action at this time.