Skip to content

Commit ef5b6ea

Browse files
authored
Merge pull request #1557 from Nexmo/APIDOC-372_fix_unpublished_blogposts
APIDOC-372: fix unpublished blog (now redirect to index if not publis…
2 parents 6d1388a + 352bd03 commit ef5b6ea

File tree

7 files changed

+98
-15
lines changed

7 files changed

+98
-15
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ jobs:
105105
env:
106106
POSTGRES_USERNAME: postgres
107107
DOCS_BASE_PATH: ./spec/fixtures
108+
BLOG_PATH: ./spec/fixtures/_blog
108109
OAS_PATH: ./spec/fixtures/api_specs/definitions
109110
FORCE_COLOR: true
110111
run: |

lib/nexmo_developer/app/controllers/blog/authors_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Blog::AuthorsController < Blog::MainController
22
def show
3-
data = BlogpostParser.fetch_all.select { |b| b['published'] && !b['outdated'] }
3+
data = BlogpostParser.fetch_all_published
44
attributes = AuthorParser.fetch_author(params[:name]) || {}
55

66
@author = Blog::Author.new(attributes).build_all_blogposts_from_author(data)

lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ class Blog::BlogpostController < Blog::MainController
55

66
def index
77
# Fetch data as Json
8-
data = BlogpostParser.fetch_all
9-
.select { |b| b['published'] && !b['outdated'] }
8+
data = BlogpostParser.fetch_all_published
109

1110
categories = CategoryParser.fetch_all_categories
1211

@@ -21,9 +20,13 @@ def index
2120
end
2221

2322
def show
24-
data = BlogpostParser.fetch_all
2523
@blogpost = Blog::Blogpost.build_blogpost_from_path(params[:blog_path], 'en')
26-
@related_blogposts = data.select { |b| b['category']['slug'] == @blogpost.category.slug && b['title'] != @blogpost.title && b['published'] && !b['outdated'] }
24+
25+
redirect_to blog_path unless @blogpost.published
26+
27+
data = BlogpostParser.fetch_all_published
28+
29+
@related_blogposts = data.select { |b| b['category']['slug'] == @blogpost.category.slug && b['title'] != @blogpost.title }
2730
.first(RELATED_FOR_PREVIEW)
2831
.sort_by { |b| b['updated_at'] }.reverse
2932
.map { |attributes| Blog::Blogpost.new attributes }

lib/nexmo_developer/app/controllers/blog/categories_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Blog::CategoriesController < Blog::MainController
22
def show
3-
data = BlogpostParser.fetch_all.select { |b| b['published'] && !b['outdated'] }
3+
data = BlogpostParser.fetch_all_published
44
attributes = CategoryParser.fetch_category(params[:slug])
55

66
@category_with_all_blogposts = Blog::Category.new(attributes).build_n_blogposts_by_category(data)

lib/nexmo_developer/app/services/blogpost_parser.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'json'
22

33
class BlogpostParser
4-
PATH_TO_INDEX = "#{Rails.configuration.blog_path}/blogposts/blogposts_info.json".freeze
4+
PATH_TO_INDEX = "#{ENV['BLOG_PATH']}/blogposts/blogposts_info.json".freeze
55

66
def self.fetch_all
77
# Add Rescue from error
@@ -10,6 +10,10 @@ def self.fetch_all
1010
JSON.parse(file)
1111
end
1212

13+
def self.fetch_all_published
14+
fetch_all.select { |b| b['published'] && !b['outdated'] }
15+
end
16+
1317
def self.build
1418
all_blogposts = []
1519

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[
2+
{
3+
"title": "Version 3.0.0 of the Vonage Python SDK is now available!",
4+
"description": "Vonage's Python Server SDK Version 3.0.0 is now available. Find out what's new!",
5+
"thumbnail": "https://d226lax1qjow5r.cloudfront.net/blog/blogposts/announcing-python-sdk-version-v3/python_sdk_updates.png",
6+
"author": {
7+
"team": true,
8+
"name": "Max Kahan",
9+
"image_url": "https://github.com/maxkahan.png",
10+
"bio": "Max is a Python Developer Advocate and Software Engineer who's passionate about technology. Interested in developer experience, machine learning, artificial intelligence, cloud development, enterprise messaging and swing dance! His training is in Physics, but now he uses his problem-solving skills daily in the technology industry.",
11+
"title": "Python Developer Advocate",
12+
"linkedin_url": "https://www.linkedin.com/in/maxkahan/",
13+
"twitter": "max_does_tech",
14+
"github_url": "https://github.com/maxkahan",
15+
"short_name": "max-kahan"
16+
},
17+
"published": true,
18+
"published_at": "2022-08-08 11:48:15 UTC",
19+
"updated_at": "2022-08-08 11:48:15 UTC",
20+
"category": {
21+
"name": "Release",
22+
"plural": "Releases",
23+
"slug": "release",
24+
"color": "#b779ff"
25+
},
26+
"tags": [
27+
"python"
28+
],
29+
"spotlight": false,
30+
"canonical": "",
31+
"outdated": false,
32+
"replacement_url": "",
33+
"locale": "en",
34+
"link": "blog/22/08/08/announcing-python-sdk-version-v3",
35+
"filename": "announcing-python-sdk-version-v3"
36+
},
37+
{
38+
"title": "How an SDK Can Add Value to REST APIs",
39+
"description": "This article provides an inside look into the design of the Java SDK's implementation of the Vonage Messages v1 API.",
40+
"thumbnail": "https://d226lax1qjow5r.cloudfront.net/blog/blogposts/how-an-sdk-can-add-value-to-rest-apis/sdk-rest-apis.png",
41+
"author": {
42+
"team": true,
43+
"name": "Sina Madani",
44+
"image_url": "https://github.com/SMadani.png",
45+
"bio": "Sina is a Java Developer Advocate at Vonage. He comes from an academic background and is generally curious about anything related to cars, computers, programming, technology and human nature. In his spare time, he can be found walking or playing competitive video games.",
46+
"title": "Java Developer Advocate",
47+
"short_name": "sina-madani"
48+
},
49+
"published": false,
50+
"published_at": "2022-08-04 11:48:15 UTC",
51+
"updated_at": "2022-08-04 11:48:16 UTC",
52+
"category": {
53+
"name": "Release",
54+
"plural": "Releases",
55+
"slug": "release",
56+
"color": "#b779ff"
57+
},
58+
"tags": [
59+
"java",
60+
"messages-v1",
61+
"messages-api"
62+
],
63+
"spotlight": false,
64+
"canonical": "",
65+
"outdated": false,
66+
"replacement_url": "",
67+
"locale": "en",
68+
"link": "blog/22/08/04/how-an-sdk-can-add-value-to-rest-apis",
69+
"filename": "how-an-sdk-can-add-value-to-rest-apis"
70+
}
71+
]
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
require 'rails_helper'
22

3-
# RSpec.describe BlogpostParser do
3+
RSpec.describe BlogpostParser do
4+
context 'self.fetch_all' do
5+
it 'can load blogposts/blogposts_info.json' do
6+
expect(BlogpostParser.fetch_all).to_not eq(nil)
7+
end
8+
end
49

5-
# context 'self.fetch_all' do
6-
# it 'can load blogposts/blogposts_info.json' do
7-
# expect(BlogpostParser.fetch_all).to_not eq(nil)
8-
# end
9-
# end
10-
11-
# end
10+
context 'self.fetch_all_published' do
11+
it 'can load published blogposts from blogposts_info.json' do
12+
expect(BlogpostParser.fetch_all).to_not eq(BlogpostParser.fetch_all_published)
13+
end
14+
end
15+
end

0 commit comments

Comments
 (0)