🐛 Fixed API excerpt field issue (#15005)

* 🐛 Fixed API excerpt field issue
ref https://github.com/TryGhost/Ghost/issues/10396

This fix now allows the API user to add field `excerpt` without the need for `plaintext` as format.
Also added new tests for these functions.
* Added new logic that takes `custom_excerpt` into account if all posts gets queried.
* Removed limits in excerpt & plaintext post.
* Updated snapshot.
This commit is contained in:
Ronald Langeveld 2022-07-06 17:57:04 +02:00 committed by GitHub
parent 9e8bbc028d
commit 2bf4344a63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 510 additions and 17 deletions

View File

@ -2,31 +2,65 @@ const readingMinutes = require('@tryghost/helpers').utils.readingMinutes;
module.exports.forPost = (frame, model, attrs) => {
const _ = require('lodash');
// This function is split up in 3 conditions for 3 different purposes:
// 1. Gets excerpt from post's plaintext. If custom_excerpt exists, it overrides the excerpt but the key remains excerpt.
if (Object.prototype.hasOwnProperty.call(frame.options, 'columns') || _.includes(frame.options.columns, 'excerpt') || _.includes(frame.options.columns, 'excerpt') && frame.options.formats && frame.options.formats.includes('plaintext')) {
if (_.includes(frame.options.columns, 'excerpt')) {
if (!attrs.custom_excerpt || attrs.custom_excerpt === null) {
let plaintext = model.get('plaintext');
if (plaintext) {
attrs.excerpt = plaintext.substring(0, 500);
} else {
attrs.excerpt = null;
}
if (!frame.options.columns.includes('custom_excerpt')) {
delete attrs.custom_excerpt;
}
} else {
attrs.excerpt = attrs.custom_excerpt;
if (!_.includes(frame.options.columns, 'custom_excerpt')) {
delete attrs.custom_excerpt;
}
}
}
}
// 2. Displays plaintext if requested by user as a field. Also works if used as format.
if (_.includes(frame.options.columns, 'plaintext') || frame.options.formats && frame.options.formats.includes('plaintext')) {
let plaintext = model.get('plaintext');
if (plaintext){
attrs.plaintext = plaintext;
} else {
delete attrs.plaintext;
}
}
if (!Object.prototype.hasOwnProperty.call(frame.options, 'columns') ||
(frame.options.columns.includes('excerpt') && frame.options.formats && frame.options.formats.includes('plaintext'))) {
if (_.isEmpty(attrs.custom_excerpt)) {
let plaintext = model.get('plaintext');
// 3. Displays excerpt if no columns was requested - specifically needed for the Admin Posts API.
if (!Object.prototype.hasOwnProperty.call(frame.options, 'columns')) {
let plaintext = model.get('plaintext');
let customExcerpt = model.get('custom_excerpt');
if (customExcerpt !== null){
attrs.excerpt = customExcerpt;
} else {
if (plaintext) {
attrs.excerpt = plaintext.substring(0, 500);
} else {
attrs.excerpt = null;
}
} else {
attrs.excerpt = attrs.custom_excerpt;
}
}
// reading_time still only works when used along with formats=html.
if (!Object.prototype.hasOwnProperty.call(frame.options, 'columns') ||
(frame.options.columns.includes('reading_time'))) {
(frame.options.columns.includes('reading_time'))) {
if (attrs.html) {
let additionalImages = 0;
if (attrs.feature_image) {
additionalImages += 1;
}
attrs.reading_time = readingMinutes(attrs.html, additionalImages);
}
}

View File

@ -7,6 +7,16 @@ const messages = {
couldNotUnderstandRequest: 'Could not understand request.'
};
// If user requested an excerpt we need to ensure plaintext and custom_excerpt is also included so we can include it when we query the database.
const requiredForExcerpt = (requestedColumns) => {
if (requestedColumns){
if (requestedColumns.includes('excerpt') && !requestedColumns.includes('plaintext') && !requestedColumns.includes('plaintext') || !requestedColumns) {
requestedColumns.push('plaintext');
requestedColumns.push('custom_excerpt');
}
}
};
/**
* @param {Bookshelf} Bookshelf
*/
@ -72,6 +82,8 @@ module.exports = function (Bookshelf) {
const options = this.filterOptions(unfilteredOptions, 'findPage');
const itemCollection = this.getFilteredCollection(options);
const requestedColumns = options.columns;
// make sure we include plaintext and custom_excerpt if excerpt is requested
requiredForExcerpt(requestedColumns);
// Set this to true or pass ?debug=true as an API option to get output
itemCollection.debug = unfilteredOptions.debug && process.env.NODE_ENV !== 'production';
@ -126,6 +138,9 @@ module.exports = function (Bookshelf) {
const options = this.filterOptions(unfilteredOptions, 'findOne');
data = this.filterData(data);
const model = this.forge(data);
const requestedColumns = options.columns;
// make sure we include plaintext and custom_excerpt if excerpt is requested
requiredForExcerpt(requestedColumns);
// @NOTE: The API layer decides if this option is allowed
if (options.filter) {

View File

@ -3350,3 +3350,430 @@ Object {
"x-powered-by": "Express",
}
`;
exports[`Posts Content API Can use post excerpt as field 1: [body] 1`] = `
Object {
"meta": Object {
"pagination": Object {
"limit": 15,
"next": null,
"page": 1,
"pages": 1,
"prev": null,
"total": 15,
},
},
"posts": Array [
Object {
"excerpt": "",
},
Object {
"excerpt": "",
},
Object {
"excerpt": "",
},
Object {
"excerpt": "markdown
",
},
Object {
"excerpt": "We've crammed the most important information to help you get started with Ghost into this one post. It's your cheat-sheet to get started, and your shortcut to advanced features.",
},
Object {
"excerpt": "How to tweak a few settings in Ghost to transform your site from a generic template to a custom brand with style and personality.",
},
Object {
"excerpt": "A full overview of all the features built into the Ghost editor, including powerful workflow automations to speed up your creative process.",
},
Object {
"excerpt": "How Ghost allows you to turn anonymous readers into an audience of active subscribers, so you know what's working and what isn't.",
},
Object {
"excerpt": "",
},
Object {
"excerpt": "A guide to collaborating with other staff users to publish, and some resources to help you with the next steps of growing your business",
},
Object {
"excerpt": "Work with all your favorite apps and tools or create your own custom integrations using the Ghost API.",
},
Object {
"excerpt": " * Lorem
* Aliquam
* Tortor
* Morbi
* Praesent
* Pellentesque
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
1234abcdefghijkl
Definition listConsectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim venia",
},
Object {
"excerpt": "testing
mctesters
* test
* line
* items
",
},
Object {
"excerpt": "HTML Ipsum Presents
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum o",
},
Object {
"excerpt": "This is my custom excerpt!",
},
],
}
`;
exports[`Posts Content API Can use post plaintext as field 1: [body] 1`] = `
Object {
"meta": Object {
"pagination": Object {
"limit": 15,
"next": null,
"page": 1,
"pages": 1,
"prev": null,
"total": 15,
},
},
"posts": Array [
Object {
"plaintext": "",
},
Object {
"plaintext": "",
},
Object {
"plaintext": "",
},
Object {
"plaintext": "markdown
",
},
Object {
"plaintext": "Hey there, welcome to your new home on the web!
Unlike social networks, this one is all yours. Publish your work on a custom domain, invite your audience to subscribe, send them new content by email newsletter, and offer premium subscriptions to generate sustainable recurring revenue to fund your work.
Ghost is an independent, open source app, which means you can customize absolutely everything. Inside the admin area, you'll find straightforward controls for changing themes, colors, navigation, logos and settings — so you can set your site up just how you like it. No technical knowledge required.
If you're feeling a little more adventurous, there's really no limit to what's possible. With just a little bit of HTML and CSS you can modify or build your very own theme from scratch, or connect to Zapier to explore advanced integrations. Advanced developers can go even further and build entirely custom workflows using the Ghost API.
This level of customization means that Ghost grows with you. It's easy to get started, but there's always another level of what's possible. So, you won't find yourself outgrowing the app in a few months time and wishing you'd chosen something more powerful!
For now, you're probably just wondering what to do first. To help get you going as quickly as possible, we've populated your site with starter content (like this post!) covering all the key concepts and features of the product.
You'll find an outline of all the different topics below, with links to each section so you can explore the parts that interest you most.
Once you're ready to begin publishing and want to clear out these starter posts, you can delete the \\"Ghost\\" staff user. Deleting an author will automatically remove all of their posts, leaving you with a clean blank canvas.
Your guide to Ghost
* Customizing your brand and site settings
* Writing & managing content, an advanced guide for creators
* Building your audience with subscriber signups
* Selling premium memberships with recurring revenue
* How to grow your business around an audience
* Setting up custom integrations and apps
If you get through all those and you're hungry for more, you can find an extensive library of content for creators over on the Ghost blog.
Getting help
If you need help, Ghost(Pro) customers can always reach our full-time support team by clicking on the Ghost(Pro) link inside their admin panel.
If you're a developer working with the codebase in a self-managed install, check out our developer community forum to chat with other users.
Have fun!",
},
Object {
"plaintext": "As discussed in the introduction post, one of the best things about Ghost is just how much you can customize to turn your site into something unique. Everything about your layout and design can be changed, so you're not stuck with yet another clone of a social network profile.
How far you want to go with customization is completely up to you, there's no right or wrong approach! The majority of people use one of Ghost's built-in themes to get started, and then progress to something more bespoke later on as their site grows.
The best way to get started is with Ghost's branding settings, where you can set up colors, images and logos to fit with your brand.
Any Ghost theme that's up to date and compatible with Ghost 4.0 and higher will reflect your branding settings in the preview window, so you can see what your site will look like as you experiment with different options.
When selecting an accent color, try to choose something which will contrast well with white text. Many themes will use your accent color as the background for buttons, headers and navigational elements. Vibrant colors with a darker hue tend to work best, as a general rule.
Installing Ghost themes
By default, new sites are created with Ghost's friendly publication theme, called Casper. Everything in Casper is optimized to work for the most common types of blog, newsletter and publication that people create with Ghost — so it's a perfect place to start.
However, there are hundreds of different themes available to install, so you can pick out a look and feel that suits you best.
Inside Ghost's theme settings you'll find 4 more official themes that can be directly installed and activated. Each theme is suited to slightly different use-cases.
* Casper (default) — Made for all sorts of blogs and newsletters
* Edition — A beautiful minimal template for newsletter authors
* Alto — A slick news/magazine style design for creators
* London — A light photography theme with a bold grid
* Ease — A library theme for organizing large content archives
And if none of those feel quite right, head on over to the Ghost Marketplace, where you'll find a huge variety of both free and premium themes.
Building something custom
Finally, if you want something completely bespoke for your site, you can always build a custom theme from scratch and upload it to your site.
Ghost's theming template files are very easy to work with, and can be picked up in the space of a few hours by anyone who has just a little bit of knowledge of HTML and CSS. Templates from other platforms can also be ported to Ghost with relatively little effort.
If you want to take a quick look at the theme syntax to see what it's like, you can browse through the files of the default Casper theme. We've added tons of inline code comments to make it easy to learn, and the structure is very readable.
{{#post}}
<article class=\\"article {{post_class}}\\">
<h1>{{title}}</h1>
{{#if feature_image}}
<img src=\\"{{feature_image}}\\" alt=\\"Feature image\\" />
{{/if}}
{{content}}
</article>
{{/post}}
See? Not that scary! But still completely optional.
If you're interested in creating your own Ghost theme, check out our extensive theme documentation for a full guide to all the different template variables and helpers which are available.",
},
Object {
"plaintext": "Ghost comes with a best-in-class editor which does its very best to get out of the way, and let you focus on your content. Don't let its minimal looks fool you, though, beneath the surface lies a powerful editing toolset designed to accommodate the extensive needs of modern creators.
For many, the base canvas of the Ghost editor will feel familiar. You can start writing as you would expect, highlight content to access the toolbar you would expect, and generally use all of the keyboard shortcuts you would expect.
Our main focus in building the Ghost editor is to try and make as many things that you hope/expect might work: actually work.
* You can copy and paste raw content from web pages, and Ghost will do its best to correctly preserve the formatting.
* Pasting an image from your clipboard will upload inline.
* Pasting a social media URL will automatically create an embed.
* Highlight a word in the editor and paste a URL from your clipboard on top: Ghost will turn it into a link.
* You can also paste (or write!) Markdown and Ghost will usually be able to auto-convert it into fully editable, formatted content.
The goal, as much as possible, is for things to work so that you don't have to think so much about the editor. You won't find any disastrous \\"block builders\\" here, where you have to open 6 submenus and choose from 18 different but identical alignment options. That's not what Ghost is about.
What you will find though, is dynamic cards which allow you to embed rich media into your posts and create beautifully laid out stories.
Using cards
You can insert dynamic cards inside post content using the + button, which appears on new lines, or by typing / on a new line to trigger the card menu. Many of the choices are simple and intuitive, like bookmark cards, which allow you to create rich links with embedded structured data:
Open Subscription PlatformsA shared movement for independent subscription data.Open Subscription Platforms
or embed cards which make it easy to insert content you want to share with your audience, from external services:
But, dig a little deeper, and you'll also find more advanced cards, like one that only shows up in email newsletters (great for personalized introductions) and a comprehensive set of specialized cards for different types of images and galleries.
Once you  start mixing text and image cards creatively, the whole narrative of the story changes. Suddenly, you're working in a new format.
As it turns out, sometimes pictures and a thousand words go together really well. Telling people a great story often has much more impact if they can feel, even for a moment, as though they were right there with you.
Galleries and image cards can be combined in so many different ways — the only limit is your imagination.
Build workflows with snippets
One of the most powerful features of the Ghost editor is the ability to create and re-use content snippets. If you've ever used an email client with a concept of saved replies then this will be immediately intuitive.
To create a snippet, select a piece of content in the editor that you'd like to re-use in future, then click on the snippet icon in the toolbar. Give your snippet a name, and you're all done. Now your snippet will be available from within the card menu, or you can search for it directly using the / command.
This works really well for saving images you might want to use often, like a company logo or team photo, links to resources you find yourself often linking to, or introductions and passages that you want to remember.
You can even build entire post templates or outlines to create a quick, re-usable workflow for publishing over time. Or build custom design elements for your post with an HTML card, and use a snippet to insert it.
Once you get a few useful snippets set up, it's difficult to go back to the old way of diving through media libraries and trawling for that one thing you know you used somewhere that one time.
Publishing and newsletters the easy way
When you're ready to publish, Ghost makes it as simple as possible to deliver your new post to all your existing members. Just hit the Preview link and you'll get a chance to see what your content looks like on Web, Mobile, Email and Social.
You can send yourself a test newsletter to make sure everything looks good in your email client, and then hit the Publish button to decide who to deliver it to.
Ghost comes with a streamlined, optimized email newsletter template that has settings built-in for you to customize the colors and typography. We've spent countless hours refining the template to make sure it works great across all email clients, and performs well for email deliverability.
So, you don't need to fight the awful process of building a custom email template from scratch. It's all done already!
The Ghost editor is powerful enough to do whatever you want it to do. With a little exploration, you'll be up and running in no time.",
},
Object {
"plaintext": "What sets Ghost apart from other products is that you can publish content and grow your audience using the same platform. Rather than just endlessly posting and hoping someone is listening, you can track real signups against your work and have them subscribe to be notified of future posts. The feature that makes all this possible is called Portal.
Portal is an embedded interface for your audience to sign up to your site. It works on every Ghost site, with every theme, and for any type of publisher.
You can customize the design, content and settings of Portal to suit your site, whether you just want people to sign up to your newsletter — or you're running a full premium publication with user sign-ins and private content.
Once people sign up to your site, they'll receive an email confirmation with a link to click. The link acts as an automatic sign-in, so subscribers will be automatically signed-in to your site when they click on it. There are a couple of interesting angles to this:
Because subscribers are automatically able to sign in and out of your site as registered members: You can (optionally) restrict access to posts and pages depending on whether people are signed-in or not. So if you want to publish some posts for free, but keep some really great stuff for members-only, this can be a great draw to encourage people to sign up!
Ghost members sign in using email authentication links, so there are no passwords for people to set or forget. You can turn any list of email subscribers into a database of registered members who can sign in to your site. Like magic.
Portal makes all of this possible, and it appears by default as a floating button in the bottom-right corner of your site. When people are logged out, clicking it will open a sign-up/sign-in window. When members are logged in, clicking the Portal button will open the account menu where they can edit their name, email, and subscription settings.
The floating Portal button is completely optional. If you prefer, you can add manual links to your content, navigation, or theme to trigger it instead.
Like this! Sign up here
As you start to grow your registered audience, you'll be able to get a sense of who you're publishing for and where those people are coming from. Best of all: You'll have a straightforward, reliable way to connect with people who enjoy your work.
Social networks go in and out of fashion all the time. Email addresses are timeless.
Growing your audience is valuable no matter what type of site you run, but if your content is your business, then you might also be interested in setting up premium subscriptions.",
},
Object {
"plaintext": "",
},
Object {
"plaintext": "As you grow, you'll probably want to start inviting team members and collaborators to your site. Ghost has a number of different user roles for your team:
Contributors
This is the base user level in Ghost. Contributors can create and edit their own draft posts, but they are unable to edit drafts of others or publish posts. Contributors are untrusted users with the most basic access to your publication.
Authors
Authors are the 2nd user level in Ghost. Authors can write, edit and publish their own posts. Authors are trusted users. If you don't trust users to be allowed to publish their own posts, they should be set as Contributors.
Editors
Editors are the 3rd user level in Ghost. Editors can do everything that an Author can do, but they can also edit and publish the posts of others - as well as their own. Editors can also invite new Contributors & Authors to the site.
Administrators
The top user level in Ghost is Administrator. Again, administrators can do everything that Authors and Editors can do, but they can also edit all site settings and data, not just content. Additionally, administrators have full access to invite, manage or remove any other user of the site.
The Owner
There is only ever one owner of a Ghost site. The owner is a special user which has all the same permissions as an Administrator, but with two exceptions: The Owner can never be deleted. And in some circumstances the owner will have access to additional special settings if applicable. For example: billing details, if using Ghost(Pro).
Ask all of your users to fill out their user profiles, including bio and social links. These will populate rich structured data for posts and generally create more opportunities for themes to fully populate their design.
If you're looking for insights, tips and reference materials to expand your content business, here's 5 top resources to get you started:
* How to create a premium newsletter (+ some case studies)
Learn how others run successful paid email newsletter products
* The ultimate guide to membership websites for creators
Tips to help you build, launch and grow your new membership business
* The Newsletter Guide
A 201 guide for taking your newsletters to the next level
* The proven way to find your niche, explained
Find the overlap and find a monetizable niche that gets noticed
* Should you launch a referral program?
Strategies for building a sustainable referral growth machine",
},
Object {
"plaintext": "It's possible to extend your Ghost site and connect it with hundreds of the most popular apps and tools using integrations.
Whether you need to automatically publish new posts on social media, connect your favorite analytics tool, sync your community or embed forms into your content — our integrations library has got it all covered with hundreds of integration tutorials.
Many integrations are as simple as inserting an embed by pasting a link, or copying a snippet of code directly from an app and pasting it into Ghost. Our integration tutorials are used by creators of all kinds to get apps and integrations up and running in no time — no technical knowledge required.
Zapier
Zapier is a no-code tool that allows you to build powerful automations, and our official integration allows you to connect your Ghost site to more than 1,000 external services.
Example: When someone new subscribes to a newsletter on a Ghost site (Trigger) then the contact information is automatically pushed into MailChimp (Action).
Here's a few of the most popular automation templates:
Custom integrations
For more advanced automation, it's possible to create custom Ghost integrations with dedicated API keys from the Integrations page within Ghost Admin.
These custom integrations allow you to use the Ghost API without needing to write code, and create powerful workflows such as sending content from your favorite desktop editor into Ghost as a new draft.",
},
Object {
"plaintext": " * Lorem
* Aliquam
* Tortor
* Morbi
* Praesent
* Pellentesque
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
1234abcdefghijkl
Definition listConsectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.Lorem ipsum dolor sit ametConsectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
* Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu. Cras consequat.
* Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.
* Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer ligula vulputate sem tristique cursus. Nam nulla quam, gravida non, commodo a, sodales sit amet, nisi.
* Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.
",
},
Object {
"plaintext": "testing
mctesters
* test
* line
* items
",
},
Object {
"plaintext": "HTML Ipsum Presents
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.
Header Level 2
1. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
2. Aliquam tincidunt mauris eu risus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.
Header Level 3
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
* Aliquam tincidunt mauris eu risus.
#header h1 a{display: block;width: 300px;height: 80px;}",
},
Object {
"plaintext": "HTML Ipsum Presents
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.
Header Level 2
1. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
2. Aliquam tincidunt mauris eu risus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.
Header Level 3
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
* Aliquam tincidunt mauris eu risus.
#header h1 a{display: block;width: 300px;height: 80px;}",
},
],
}
`;

View File

@ -309,4 +309,18 @@ describe('Posts Content API', function () {
tiersPostData.tiers.length.should.eql(1);
});
it('Can use post excerpt as field', async function () {
await agent
.get(`posts/?fields=excerpt`)
.expectStatus(200)
.matchBodySnapshot();
});
it('Can use post plaintext as field', async function () {
await agent
.get(`posts/?fields=plaintext`)
.expectStatus(200)
.matchBodySnapshot();
});
});

View File

@ -29,7 +29,6 @@ Object {
"og_description": null,
"og_image": null,
"og_title": null,
"plaintext": null,
"primary_tag": null,
"published_at": null,
"slug": "testing-post-added-webhook",
@ -107,7 +106,6 @@ Object {
"og_description": null,
"og_image": null,
"og_title": null,
"plaintext": null,
"primary_tag": null,
"published_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"slug": "webhookz",

View File

@ -4,7 +4,10 @@ const extraAttrsUtil = require('../../../../../../../../core/server/api/endpoint
describe('Unit: endpoints/utils/serializers/output/utils/extra-attrs', function () {
const frame = {
options: {}
// Question: is it okay to use actual column values here that the forPost function in extra-attrs would expect?
options: {
columns: ['excerpt', 'custom_excerpt', 'plaintext']
}
};
let model;
@ -18,10 +21,7 @@ describe('Unit: endpoints/utils/serializers/output/utils/extra-attrs', function
describe('for post', function () {
it('respects custom excerpt', function () {
const attrs = {custom_excerpt: 'custom excerpt'};
extraAttrsUtil.forPost(frame, model, attrs);
model.get.called.should.be.false();
attrs.excerpt.should.eql(attrs.custom_excerpt);
});
@ -36,14 +36,19 @@ describe('Unit: endpoints/utils/serializers/output/utils/extra-attrs', function
it('has excerpt when plaintext is null', function () {
model.get.withArgs('plaintext').returns(null);
const attrs = {};
extraAttrsUtil.forPost(frame, model, attrs);
model.get.called.should.be.true();
attrs.should.have.property('excerpt');
(attrs.excerpt === null).should.be.true();
});
it('has excerpt when no columns are passed', function () {
delete frame.options.columns;
const attrs = {};
extraAttrsUtil.forPost(frame, model, attrs);
model.get.called.should.be.true();
attrs.should.have.property('excerpt');
});
});
});