274 lines
6.8 KiB
JavaScript
274 lines
6.8 KiB
JavaScript
import { defineComponent, toRefs, computed, watch, useSlots, useSSRContext, h } from 'vue';
|
|
import { u as useAsyncData } from './asyncData-e8a8bfb6.mjs';
|
|
import { hash } from 'ohash';
|
|
import { q as queryContent } from './query-e0164f92.mjs';
|
|
import '../server.mjs';
|
|
import 'ofetch';
|
|
import 'hookable';
|
|
import 'unctx';
|
|
import 'h3';
|
|
import '@unhead/ssr';
|
|
import 'unhead';
|
|
import '@unhead/shared';
|
|
import 'vue-router';
|
|
import 'ufo';
|
|
import '@intlify/core-base';
|
|
import 'cookie-es';
|
|
import 'is-https';
|
|
import 'anu-vue';
|
|
import 'vue/server-renderer';
|
|
import 'defu';
|
|
import '../../nitro/node-server.mjs';
|
|
import 'node-fetch-native/polyfill';
|
|
import 'node:http';
|
|
import 'node:https';
|
|
import 'destr';
|
|
import 'unenv/runtime/fetch/index';
|
|
import 'scule';
|
|
import 'klona';
|
|
import 'unstorage';
|
|
import 'unstorage/drivers/fs';
|
|
import 'unstorage/drivers/overlay';
|
|
import 'unstorage/drivers/memory';
|
|
import 'radix3';
|
|
import 'node:fs';
|
|
import 'node:url';
|
|
import 'pathe';
|
|
import '@intlify/bundle-utils';
|
|
import 'unified';
|
|
import 'mdast-util-to-string';
|
|
import 'micromark/lib/preprocess.js';
|
|
import 'micromark/lib/postprocess.js';
|
|
import 'unist-util-stringify-position';
|
|
import 'micromark-util-character';
|
|
import 'micromark-util-chunked';
|
|
import 'micromark-util-resolve-all';
|
|
import 'remark-emoji';
|
|
import 'rehype-slug';
|
|
import 'remark-squeeze-paragraphs';
|
|
import 'rehype-external-links';
|
|
import 'remark-gfm';
|
|
import 'rehype-sort-attribute-values';
|
|
import 'rehype-sort-attributes';
|
|
import 'rehype-raw';
|
|
import 'remark-mdc';
|
|
import 'remark-parse';
|
|
import 'remark-rehype';
|
|
import 'mdast-util-to-hast';
|
|
import 'detab';
|
|
import 'unist-builder';
|
|
import 'mdurl';
|
|
import 'slugify';
|
|
import 'unist-util-position';
|
|
import 'unist-util-visit';
|
|
import 'shiki-es';
|
|
import 'unenv/runtime/npm/consola';
|
|
import './utils-6d756e03.mjs';
|
|
import './preview-38d6e135.mjs';
|
|
|
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
name: "ContentQuery",
|
|
props: {
|
|
/**
|
|
* The path of the content to load from content source.
|
|
*/
|
|
path: {
|
|
type: String,
|
|
required: false,
|
|
default: void 0
|
|
},
|
|
/**
|
|
* Select a subset of fields
|
|
*/
|
|
only: {
|
|
type: Array,
|
|
required: false,
|
|
default: void 0
|
|
},
|
|
/**
|
|
* Remove a subset of fields
|
|
*/
|
|
without: {
|
|
type: Array,
|
|
required: false,
|
|
default: void 0
|
|
},
|
|
/**
|
|
* Filter results
|
|
*/
|
|
where: {
|
|
type: Object,
|
|
required: false,
|
|
default: void 0
|
|
},
|
|
/**
|
|
* Sort results
|
|
*/
|
|
sort: {
|
|
type: Object,
|
|
required: false,
|
|
default: void 0
|
|
},
|
|
/**
|
|
* Limit number of results
|
|
*/
|
|
limit: {
|
|
type: Number,
|
|
required: false,
|
|
default: void 0
|
|
},
|
|
/**
|
|
* Skip number of results
|
|
*/
|
|
skip: {
|
|
type: Number,
|
|
required: false,
|
|
default: void 0
|
|
},
|
|
/**
|
|
* Filter contents based on locale
|
|
*/
|
|
locale: {
|
|
type: String,
|
|
required: false,
|
|
default: void 0
|
|
},
|
|
/**
|
|
* A type of query to be made.
|
|
*/
|
|
find: {
|
|
type: String,
|
|
required: false,
|
|
default: void 0
|
|
}
|
|
},
|
|
async setup(props) {
|
|
const {
|
|
path,
|
|
only,
|
|
without,
|
|
where,
|
|
sort,
|
|
limit,
|
|
skip,
|
|
locale,
|
|
find
|
|
} = toRefs(props);
|
|
const isPartial = computed(() => {
|
|
var _a;
|
|
return (_a = path.value) == null ? void 0 : _a.includes("/_");
|
|
});
|
|
watch(() => props, () => refresh(), { deep: true });
|
|
const { data, refresh } = await useAsyncData(
|
|
`content-query-${hash(props)}`,
|
|
() => {
|
|
let queryBuilder;
|
|
if (path.value) {
|
|
queryBuilder = queryContent(path.value);
|
|
} else {
|
|
queryBuilder = queryContent();
|
|
}
|
|
if (only.value) {
|
|
queryBuilder = queryBuilder.only(only.value);
|
|
}
|
|
if (without.value) {
|
|
queryBuilder = queryBuilder.without(without.value);
|
|
}
|
|
if (where.value) {
|
|
queryBuilder = queryBuilder.where(where.value);
|
|
}
|
|
if (sort.value) {
|
|
queryBuilder = queryBuilder.sort(sort.value);
|
|
}
|
|
if (limit.value) {
|
|
queryBuilder = queryBuilder.limit(limit.value);
|
|
}
|
|
if (skip.value) {
|
|
queryBuilder = queryBuilder.skip(skip.value);
|
|
}
|
|
if (locale.value) {
|
|
queryBuilder = queryBuilder.where({ _locale: locale.value });
|
|
}
|
|
if (find.value === "one") {
|
|
return queryBuilder.findOne();
|
|
}
|
|
if (find.value === "surround") {
|
|
if (!path.value) {
|
|
console.warn("[Content] Surround queries requires `path` prop to be set.");
|
|
console.warn("[Content] Query without `path` will return regular `find()` results.");
|
|
return queryBuilder.find();
|
|
}
|
|
return queryBuilder.findSurround(path.value);
|
|
}
|
|
return queryBuilder.find();
|
|
}
|
|
);
|
|
return {
|
|
isPartial,
|
|
data,
|
|
refresh
|
|
};
|
|
},
|
|
/**
|
|
* Content not found fallback
|
|
* @slot not-found
|
|
*/
|
|
render(ctx) {
|
|
var _a;
|
|
const slots = useSlots();
|
|
const {
|
|
// Setup
|
|
data,
|
|
refresh,
|
|
isPartial,
|
|
// Props
|
|
path,
|
|
only,
|
|
without,
|
|
where,
|
|
sort,
|
|
limit,
|
|
skip,
|
|
locale,
|
|
find
|
|
} = ctx;
|
|
const props = {
|
|
path,
|
|
only,
|
|
without,
|
|
where,
|
|
sort,
|
|
limit,
|
|
skip,
|
|
locale,
|
|
find
|
|
};
|
|
if (props.find === "one") {
|
|
if (!data && (slots == null ? void 0 : slots["not-found"])) {
|
|
return slots["not-found"]({ props, ...this.$attrs });
|
|
}
|
|
if ((slots == null ? void 0 : slots.empty) && (data == null ? void 0 : data._type) === "markdown" && !((_a = data == null ? void 0 : data.body) == null ? void 0 : _a.children.length)) {
|
|
return slots.empty({ props, ...this.$attrs });
|
|
}
|
|
} else if (!data || !data.length) {
|
|
if (slots == null ? void 0 : slots["not-found"]) {
|
|
return slots["not-found"]({ props, ...this.$attrs });
|
|
}
|
|
}
|
|
if (slots == null ? void 0 : slots.default) {
|
|
return slots.default({ data, refresh, isPartial, props, ...this.$attrs });
|
|
}
|
|
const emptyNode = (slot, data2) => h("pre", null, JSON.stringify({ message: "You should use slots with <ContentQuery>!", slot, data: data2 }, null, 2));
|
|
return emptyNode("default", { data, props, isPartial });
|
|
}
|
|
});
|
|
const _sfc_setup = _sfc_main.setup;
|
|
_sfc_main.setup = (props, ctx) => {
|
|
const ssrContext = useSSRContext();
|
|
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("node_modules/.pnpm/@nuxt+content@2.6.0_rollup@2.79.1/node_modules/@nuxt/content/dist/runtime/components/ContentQuery.vue");
|
|
return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
|
|
};
|
|
|
|
export { _sfc_main as default };
|
|
//# sourceMappingURL=ContentQuery-c9561d42.mjs.map
|