Skip to content

Commit

Permalink
✨ Finish cli
Browse files Browse the repository at this point in the history
  • Loading branch information
thiamsantos committed Apr 2, 2017
1 parent 20f2559 commit 12d1feb
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 62 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Thiago Santos
Copyright (c) 2017 Gustavo Quinalha

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
99 changes: 96 additions & 3 deletions bin/seotopper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const questions = [
{
type: 'input',
name: 'title',
message: 'What\'s the title of your page (required)',
message: 'What\'s the title of your page',
validate: value => {
if (value === '') {
return 'Please enter a title'
Expand Down Expand Up @@ -95,11 +95,104 @@ const questions = [
type: 'input',
name: 'themeColor',
message: 'What\'s the theme-color of your page'
},
{
type: 'confirm',
name: 'facebook',
message: 'Do you wanna seo for facebook'
},
{
type: 'list',
name: 'facebookType',
message: 'What\'s the type of your page',
choices: [
'website',
'blog',
'article',
'activity',
'sport',
'company',
'restaurant',
'hotel',
'cause',
'band',
'government',
'non_profit',
'school',
'university',
'actor',
'athlete',
'city',
'country',
'album',
'book',
'drink',
'game',
'product',
'song',
'movie'
],
when: answers => {
return answers.facebook
}
},
{
type: 'input',
name: 'facebookSiteName',
message: 'What\'s the name of your page on facebook',
when: answers => {
return answers.facebook
}
},
{
type: 'input',
name: 'facebookLocale',
message: 'What\'s the locale of your page on facebook',
when: answers => {
return answers.facebook
}
},
{
type: 'input',
name: 'facebookId',
message: 'What\'s the id of your page on facebook',
when: answers => {
return answers.facebook
}
},
{
type: 'input',
name: 'facebookAdmins',
message: 'What are the admins of your page on facebook',
when: answers => {
return answers.facebook
}
},
{
type: 'confirm',
name: 'twitter',
message: 'Do you wanna seo for twitter'
},
{
type: 'list',
name: 'twitterCard',
message: 'Which twitter do you want',
choices: [
'Summary',
'Product',
'Photo',
'Summary Large Image',
'Player',
'App',
'Gallery'
],
when: answers => {
return answers.twitter
}
}
]

inquirer.prompt(questions).then(answers => {
const generatedSEO = seotopper(answers)
// Process.stdout.write(generatedSEO)
console.log(generatedSEO)
process.stdout.write(generatedSEO)
})
26 changes: 19 additions & 7 deletions lib/seotopper.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,33 @@ function seotopper(args) {
${args.facebook ?
`<!-- markup for facebook -->
<meta property="og:type" content="${args.facebook.type}"/>
<meta property="og:type" content="${args.facebookType}"/>
<meta property="og:title" content="${args.title}"/>
<meta property="og:url" content="http://meusite.com.br"/>
<meta property="og:site_name" content="${args.facebook.siteName}"/>
<meta property="og:url" content="${args.canonical}"/>
${args.facebookSiteName ?
`<meta property="og:site_name" content="${args.facebookSiteName}"/>` :
''
}
<meta property="og:image" content="${args.image}"/>
<meta property="og:description" content="${args.description}"/>
<meta property="og:locale" content="${args.facebook.locale}"/>
<meta property="fb:app_id" content="${args.facebook.id}"/>
<meta property="fb:admins" content="${args.facebook.admins}"/>` :
${args.facebookLocale ?
`<meta property="og:locale" content="${args.facebookLocale}"/>` :
''
}
${args.facebookId ?
`<meta property="fb:app_id" content="${args.facebookId}"/>` :
''
}
${args.facebookAdmins ?
`<meta property="fb:admins" content="${args.facebookAdmins}"/>` :
''
}` :
''
}
${args.twitter ?
`<!-- markup for twitter -->
<meta name="twitter:card" content="${args.twitter.card}"/>
<meta name="twitter:card" content="${args.twitterCard}"/>
<meta name="twitter:title" content="${args.title}"/>
<meta name="twitter:description" content="${args.description}"/>
<meta name="twitter:creator" content="${args.author}"/>
Expand Down
92 changes: 41 additions & 51 deletions test/seotopper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ test('main funcionality', t => {
robots: 'index/follow',
themeColor: '#f00',
image: 'https://sua-url.com.br/images/intro.jpg',
facebook: {
type: 'website',
siteName: 'Exemplo',
locale: 'pt_BR',
id: '5349',
admins: '123456789'
},
twitter: {
card: 'summary'
}
facebook: true,
facebookType: 'website',
facebookSiteName: 'Exemplo',
facebookLocale: 'pt_BR',
facebookId: '5349',
facebookAdmins: '123456789',
twitter: true,
twitterCard: 'summary'
})

const expected = `<title>Título da minha página</title>
Expand All @@ -42,7 +40,7 @@ test('main funcionality', t => {
<!-- markup for facebook -->
<meta property="og:type" content="website"/>
<meta property="og:title" content="Título da minha página"/>
<meta property="og:url" content="http://meusite.com.br"/>
<meta property="og:url" content="https://sua-url.com.br"/>
<meta property="og:site_name" content="Exemplo"/>
<meta property="og:image" content="https://sua-url.com.br/images/intro.jpg"/>
<meta property="og:description" content="Descrição da minha página"/>
Expand Down Expand Up @@ -79,16 +77,14 @@ test('base should be optional', t => {
robots: 'index/follow',
themeColor: '#f00',
image: 'https://sua-url.com.br/images/intro.jpg',
facebook: {
type: 'website',
siteName: 'Exemplo',
locale: 'pt_BR',
id: '5349',
admins: '123456789'
},
twitter: {
card: 'summary'
}
facebook: true,
facebookType: 'website',
facebookSiteName: 'Exemplo',
facebookLocale: 'pt_BR',
facebookId: '5349',
facebookAdmins: '123456789',
twitter: true,
twitterCard: 'summary'
})

t.notRegex(actual, /rel="base"/)
Expand All @@ -103,16 +99,14 @@ test('sitemap should be optional', t => {
robots: 'index/follow',
themeColor: '#f00',
image: 'https://sua-url.com.br/images/intro.jpg',
facebook: {
type: 'website',
siteName: 'Exemplo',
locale: 'pt_BR',
id: '5349',
admins: '123456789'
},
twitter: {
card: 'summary'
}
facebook: true,
facebookType: 'website',
facebookSiteName: 'Exemplo',
facebookLocale: 'pt_BR',
facebookId: '5349',
facebookAdmins: '123456789',
twitter: true,
twitterCard: 'summary'
})

t.notRegex(actual, /rel="sitemap"/)
Expand All @@ -126,16 +120,14 @@ test('themeColor should be optional', t => {
canonical: 'https://sua-url.com.br',
robots: 'index/follow',
image: 'https://sua-url.com.br/images/intro.jpg',
facebook: {
type: 'website',
siteName: 'Exemplo',
locale: 'pt_BR',
id: '5349',
admins: '123456789'
},
twitter: {
card: 'summary'
}
facebook: true,
facebookType: 'website',
facebookSiteName: 'Exemplo',
facebookLocale: 'pt_BR',
facebookId: '5349',
facebookAdmins: '123456789',
twitter: true,
twitterCard: 'summary'
})

t.notRegex(actual, /name="theme-color"/)
Expand All @@ -151,9 +143,8 @@ test('facebook should be optional', t => {
canonical: 'https://sua-url.com.br',
robots: 'index/follow',
image: 'https://sua-url.com.br/images/intro.jpg',
twitter: {
card: 'summary'
}
twitter: true,
twitterCard: 'summary'
})
t.notRegex(actual, /property="og:type"/)
t.notRegex(actual, /property="og:title"/)
Expand All @@ -174,13 +165,12 @@ test('twitter should be optional', t => {
canonical: 'https://sua-url.com.br',
robots: 'index/follow',
image: 'https://sua-url.com.br/images/intro.jpg',
facebook: {
type: 'website',
siteName: 'Exemplo',
locale: 'pt_BR',
id: '5349',
admins: '123456789'
}
facebook: true,
facebookType: 'website',
facebookSiteName: 'Exemplo',
facebookLocale: 'pt_BR',
facebookId: '5349',
facebookAdmins: '123456789'
})
t.notRegex(actual, /name="twitter:card"/)
t.notRegex(actual, /name="twitter:title"/)
Expand Down

0 comments on commit 12d1feb

Please sign in to comment.