Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from optikfluffel/rss
Browse files Browse the repository at this point in the history
Add RSS feed of jobs at /feed
  • Loading branch information
rizafahmi committed Aug 4, 2015
2 parents e1590ef + 8fe4c23 commit c3652be
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ erl_crash.dump
# Since we are building assets from web/static,
# we ignore priv/static. You may want to comment
# this depending on your deployment strategy.
/priv/static/
/priv/static/css
/priv/static/js

# The config/prod.secret.exs file by default contains sensitive
# data and you should not commit it into version control.
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ defmodule ElixirJobs.Mixfile do
{:exrethinkdb, github: "hamiltop/exrethinkdb", ref: "55fb5b5ed892f28b7ae8ee1b2f8e54fb651bd611"},
{:timex, "~> 0.13.4"},
{:earmark, "~> 0.1.17"},
{:comeonin, "~> 1.0"}
{:comeonin, "~> 1.0"},
{:rss, "~> 0.2.1"}
]
end
end
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
"plug": {:hex, :plug, "0.14.0"},
"poison": {:hex, :poison, "1.4.0"},
"ranch": {:hex, :ranch, "1.1.0"},
"rss": {:hex, :rss, "0.2.1"},
"timex": {:hex, :timex, "0.13.5"}}
48 changes: 48 additions & 0 deletions web/controllers/feed_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
defmodule ElixirJobs.FeedController do
use ElixirJobs.Web, :controller
use Timex

alias Exrethinkdb.Query
alias ElixirJobs.Repo

@title "ElixirDose Jobs"
@baseurl "http://jobs.elixirdose.com"
@description "Elixir Jobs is the best place to find, list jobs and developer community space specifically for Elixir Programming Language."
@lang "en-us"

defp format_rfc(date) do
date |> DateFormat.format!("%a, %d %b %Y %H:%M:%S %z", :strftime)
end

defp job_to_rss_item(job) do
date = job["date_created"] |> Date.from(:secs, :epoch)
|> format_rfc

RSS.item(
job["title"],
job["description"],
date,
"#{@baseurl}/job/#{job["id"]}",
job["id"]
)
end

def index(conn, _params) do
date = Date.now |> format_rfc

channel = RSS.channel(
@title,
@baseurl,
@description,
date,
"lang (#{@lang})"
)

items = Query.table("jobs") |> Repo.run
|> Map.get(:data)
|> Enum.map(&job_to_rss_item(&1))

conn |> put_resp_content_type("application/xml")
|> text(RSS.feed(channel, items))
end
end
32 changes: 16 additions & 16 deletions web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ defmodule ElixirJobs.Router do
plug :protect_from_forgery
end

pipeline :api do
plug :accepts, ["json"]
pipeline :rss do
plug :accepts, ["rss"]
end

scope "/", ElixirJobs do
pipe_through :browser # Use the default browser stack

# resources "/", PageController
get "/", PageController, :index
get "/job/new", PageController, :new
get "/job/:id", PageController, :show
get "/", PageController, :index
get "/job/new", PageController, :new
get "/job/:id", PageController, :show
post "/job", PageController, :create

get "/users/login", UserController, :login
get "/users/login", UserController, :login
post "/users/process_login", UserController, :process_login
get "/users/logout", UserController, :logout

post "/users", UserController, :create
get "/users/new_profile", UserController, :new_profile
get "/users/edit_profile", UserController, :edit_profile
get "/users/new_profile", UserController, :new_profile
get "/users/edit_profile", UserController, :edit_profile
post "/users/profile", UserController, :create_profile
post "/users/edit_profile", UserController, :update_profile
get "/users/logout", UserController, :logout

get "/dev/:id", DevController, :show

get "/dev/:id", DevController, :show
end

# Other scopes may use custom stacks.
# scope "/api", ElixirJobs do
# pipe_through :api
# end
scope "/feed", ElixirJobs do
pipe_through :rss # Use the rss stack

get "/", FeedController, :index
end
end
2 changes: 2 additions & 0 deletions web/templates/layout/app.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<meta name="description" content="Elixir Jobs is the best place to find, list jobs and developer community space specifically for Elixir Programming Language."/>
<link rel="canonical" href="http://jobs.elixirdose.com"/>
<link rel="alternate" type="application/rss+xml" title="RSS"
href="http://jobs.elixirdose.com/feed">
<!-- <link rel="publisher" href="https://plus.google.com/+AppscoId"/> -->
<meta property="og:locale" content="en_US"/>
<meta property="og:type" content="website"/>
Expand Down

0 comments on commit c3652be

Please sign in to comment.