Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
artstorm committed Jul 19, 2020
2 parents 42b26d1 + 8e3d021 commit 5c69a81
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eleventy-plugin-seo",
"version": "0.5.0",
"version": "0.5.1",
"description": "Eleventy plugin to generate meta tags for improved SEO.",
"main": ".eleventy.js",
"scripts": {
Expand Down Expand Up @@ -31,6 +31,7 @@
"prettier": "^1.18.2"
},
"dependencies": {
"html-entities": "^1.2.1"
"html-entities": "^1.2.1",
"lodash": "^4.17.19"
}
}
9 changes: 7 additions & 2 deletions src/Config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const { merge } = require("lodash");

class Config {
constructor(config = {}) {
const defaults = {
url: ""
url: "",
options: {
twitterCardType: "summary"
}
};
config = { ...defaults, ...config };
config = merge(defaults, config);

this.config = config;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Tags/TwitterCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TwitterCard extends BaseTag {
...scope.contexts[0],
siteTwitter,
image: this.useImageWithBaseURL(this.config) ? baseImage : image,
cardType: this.config.options && this.config.options.twitterCardType || 'summary'
cardType: this.keyPathVal(this, "options.twitterCardType")
};

const source = this.loadTemplate("twittercard.liquid");
Expand Down Expand Up @@ -58,7 +58,7 @@ class TwitterCard extends BaseTag {
...context.ctx,
siteTwitter,
image: self.useImageWithBaseURL(self.config) ? baseImage : image,
cardType: self.config.options && self.config.options.twitterCardType || 'summary'
cardType: self.keyPathVal(self, "options.twitterCardType")
};

const template = self.loadTemplate("twittercard.njk");
Expand Down
7 changes: 7 additions & 0 deletions test/ConfigTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ test("Config gets default values", t => {

t.is("", config.get().url);
});

test("Config can merge deep", t => {
const config = new Config({ options: { foo: "bar" } });

t.is("bar", config.get().options.foo);
t.is("summary", config.get().options.twitterCardType);
});
52 changes: 52 additions & 0 deletions test/Tags/TwitterCardTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,55 @@ test("nunjucks: image set in front matter with imageWithBaseUrl set to true shou

t.is(result.context.image, "https://example.com/foo.jpg");
});

test("liquid: card type should be set to summary by default", t => {
const config = new Config();
const twitterCard = new TwitterCard(config);
const result = twitterCard.nunjucksRender(
twitterCard,
t.context.nunjucksContextMock
);

t.log(result);

t.is(result.context.cardType, "summary");
});

test("nunjucks: liquid: card type should be set to summary by default", t => {
const config = new Config();
const twitterCard = new TwitterCard(config);
const result = twitterCard.nunjucksRender(
twitterCard,
t.context.nunjucksContextMock
);

t.is(result.context.cardType, "summary");
});

test("liquid: card type should be set to summary_large_image", t => {
const config = new Config({
options: { twitterCardType: "summary_large_image" }
});
const twitterCard = new TwitterCard(config);
const result = twitterCard.nunjucksRender(
twitterCard,
t.context.nunjucksContextMock
);

t.log(result);

t.is(result.context.cardType, "summary_large_image");
});

test("nunjucks: liquid: card type should be set to summary_large_image", t => {
const config = new Config({
options: { twitterCardType: "summary_large_image" }
});
const twitterCard = new TwitterCard(config);
const result = twitterCard.nunjucksRender(
twitterCard,
t.context.nunjucksContextMock
);

t.is(result.context.cardType, "summary_large_image");
});

0 comments on commit 5c69a81

Please sign in to comment.