Skip to content

Commit

Permalink
Merge pull request #111 from augusto-herrmann/update_nodejs_packages
Browse files Browse the repository at this point in the history
Update nodejs packages
  • Loading branch information
todrobbins authored Sep 9, 2021
2 parents 38935c2 + 4e6f9c9 commit e4675c6
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 62 deletions.
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# DESCRIPTION: publicbodies.org website
# BUILD: docker build --rm -t publicbodies .
#
# If you want to just build the documentation portal locally, do:
# docker build --rm -t publicbodies .
# to build the container, then run
# docker run --rm --volume="$PWD:/home/node/portal" -p 3000:3000 -it publicbodies node index.js
# open http://localhost:3000 on your browser to see the portal.

FROM node:12

# Never prompt the user for choices on installation/configuration of packages
ENV DEBIAN_FRONTEND noninteractive
ENV TERM linux
ENV NODE_ENV=production
# from https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#global-npm-dependencies
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin

# use non-priviledged user provided by node's docker image
USER node

# install dependencies
RUN mkdir -p /home/node/portal
COPY ./package.json /home/node/portal/package.json
WORKDIR /home/node/portal
RUN npm install .

# port Docusaurus runs on
EXPOSE 3000
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,37 @@ Packages, visit http://specs.frictionlessdata.io/.

The website is a node webapp. To get it running:

1. Install node and npm (>= 0.8)
1. Install node and npm (>= 12). Alternatively, install Docker.

2. Get the code

```
git clone https://github.com/okfn/publicbodies
```

3. Install the dependencies (make sure you are in the publicbodies directory)

```
npm install .
```

If you're using Docker, build the container instead:

```
docker build --rm -t publicbodies .
```

4. Run the webapp:

```
node index.js
```

If you're using Docker, start the container instead:

```
docker run --rm --volume="$PWD:/home/node/portal" -p 3000:3000 -it publicbodies node index.js
```

The list of outstanding issues is at: <https://github.com/okfn/publicbodies/issues>

Expand Down
5 changes: 5 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build:
docker:
web: Dockerfile
run:
web: node index.js
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*/

var express = require('express'),
favicon = require('serve-favicon'),
morgan = require('morgan'),
lessMiddleware = require('less-middleware'),
routes = require('./routes'),
http = require('http'),
path = require('path'),
Expand All @@ -12,16 +15,11 @@ var express = require('express'),
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(require('less-middleware')({
src: __dirname + '/public'
}));
app.set('view engine', 'pug');
app.use(favicon(path.join(__dirname, 'public', 'images', 'favicon.ico')));
app.use(morgan('dev'));
app.use(lessMiddleware(__dirname + '/public'));
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);

// development only
if ('development' === app.get('env')) {
Expand Down
37 changes: 19 additions & 18 deletions lib/db.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var async = require('async'),
Dirty = require('dirty'),
db = new Dirty(),
csv = require('csv'),
csv = require('csv-parse'),
fs = require('fs'),
path = require('path');

Expand Down Expand Up @@ -29,27 +29,28 @@ function processFile(file, callback) {

if (/\.csv$/.test(file)) {
console.log("Processing %s...", file);
csv().from(path.resolve('data', file), {
const content = fs.readFileSync(path.resolve('data', file));
csv(content, {
columns: true
}).on('record', function(record, idx) {
var key = record.id;
tokens = key.split('/')
;
if (!key || !record.jurisdiction_code) {
// console.log(file, idx, key);
return;
}
record.jurisdiction_code = record.jurisdiction_code.toUpperCase();
record.jurisdiction = jurisdictions[record.jurisdiction_code];
record.slug = tokens[1];
record.type = 'body';
db.set(key, record);
count++;
}).on('end', function() {
}, function(err, records){
records.forEach(function(record, idx, records){
if (!record.id || !record.jurisdiction_code) {
// console.log(file, idx, key);
return;
}
var key = record.id,
tokens = key.split('/');
record.jurisdiction_code = record.jurisdiction_code.toUpperCase();
record.jurisdiction = jurisdictions[record.jurisdiction_code];
record.slug = tokens[1];
record.type = 'body';
db.set(key, record);
count++;
});
console.log("Added %d bodies from %s", count, file);

callback();
});
})
} else {
callback();
}
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "publicbodies",
"version": "0.0.1",
"version": "0.1.0",
"description": "A database of public bodies such as government departments, ministries etc.",
"main": "site/make.js",
"directories": {
Expand Down Expand Up @@ -30,13 +30,15 @@
"readmeFilename": "README.md",
"gitHead": "05c0380d7adbbc2dc74238a2ca5354d8401caf38",
"dependencies": {
"csv": "~0.3.0",
"express": "~3.2.6",
"jade": "~0.31.2",
"pouchdb": "0.0.13",
"less-middleware": "~0.1.12",
"async": "~0.2.9",
"csv": "~5.0.0",
"dirty": "~0.9.7",
"express": "^4.7.4",
"less-middleware": "~3.1.0",
"morgan": "~1.10.0",
"pouchdb": "~7.2.2",
"pug": "~3.0.2",
"serve-favicon": "^2.5.0",
"underscore": "~1.4.4"
}
}
Binary file added public/images/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion public/stylesheets/bootstrap/navbar.less
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
.navbar-static-top .container,
.navbar-fixed-top .container,
.navbar-fixed-bottom .container {
#grid > .core > .span(@gridColumns);
// #grid > .core > .span(@gridColumns);
}

// Fixed to top
Expand Down
19 changes: 10 additions & 9 deletions views/body.jade → views/body.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,45 @@ extends layout
block content
.row
.span12
a.btn.btn-large(href="/#{jurisdiction_code}")
a.btn.btn-large(href=`/${jurisdiction_code}`)
i.icon-level-up
| #{jurisdiction}
.view
h2
=name
- if (abbreviation)
if (abbreviation)
|
small.abbr=abbreviation
.attributes.dl-horizontal
dt Home page
dd
a(href="#{url}")=name
a(href=`${url}`)=name
dt E-Mail
dd=email
dt Address
dd
- if (address)
if (address)
address
pre=address
dt Classification
dd=classification
- if (parentBody)
if (parentBody)
dt Parent Body
dd
a(href="/#{parentBody.id}")=parentBody.name
a(href=`/${parentBody.id}`)=parentBody.name
dt Jurisdiction
dd #{jurisdiction} (#{jurisdiction_code})
dt Tags
dd=tags
dt Description
-if (description)
if (description)
dd.description
blockquote=description

.well
p.source Source: <a href="#{source_url}">#{source_url}</a>
p.source Source:
a(href=`${source_url}`) #{source_url}
p
a.btn.btn-success(href="#{slug}.json")
a.btn.btn-success(href=`${slug}.json`)
i.icon-download-alt
| JSON
23 changes: 10 additions & 13 deletions views/index.jade → views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ block content
.row
.span8
h1 Jurisdictions
- each jurisdiction in juris
.row-fluid.jurisdiction
a(href="/#{jurisdiction.key}")
.span5.title
| #{jurisdiction.name}
.span2.code
| #{jurisdiction.key.toUpperCase()}
.span3
| #{jurisdiction.count} bodies
.span2.download
a.btn.btn-inverse(href="https://github.com/okfn/publicbodies/raw/master/data/#{jurisdiction.key}.csv")
i.icon-download-alt
| csv
each jurisdiction in juris
.row-fluid.jurisdiction
a(href=`/${jurisdiction.key}`)
.span5.title= jurisdiction.name
.span2.code= jurisdiction.key.toUpperCase()
.span3= jurisdiction.count + ' bodies'
.span2.download
a.btn.btn-inverse(href=`https://github.com/okfn/publicbodies/raw/master/data/${jurisdiction.key}.csv`)
i.icon-download-alt
| csv

.span4.sidebar
h3
Expand Down
6 changes: 3 additions & 3 deletions views/jurisdiction.jade → views/jurisdiction.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ extends layout
block content
.row
.span12
h1 #{name} (#{code})
h1= name + ' (' + code + ')'
.row
.span12
table.table.table-striped
tbody
- each body in bodies
each body in bodies
tr
td
a(href="/#{body.id}") #{body.name}
a(href=`/${body.id}`)= body.name
4 changes: 2 additions & 2 deletions views/layout.jade → views/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ doctype 5
html
head
title
- if (pageTitle)
if (pageTitle)
| #{pageTitle} &mdash;
| Public Bodies
link(rel='stylesheet', href='/stylesheets/publicbodies.css')
Expand All @@ -29,7 +29,7 @@ html
footer.footer
.container
p
| © 2011-2013: An
| © 2011-2021: An
a(href='http://okfn.org') Open Knowledge Foundation
| project.
a(href='https://okfn.org/privacy-policy/') Privacy policy
Expand Down
File renamed without changes.

0 comments on commit e4675c6

Please sign in to comment.