Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions _layouts/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,32 @@
{% if page.source %}
{% if page.branch %}
{% assign repo-branch = page.source | append: '/tree/' | append: page.branch %}
{% assign readme-file = page.source | append: '-' | append: page.branch %}
{% assign readme-file = page.source | append: '-' | append: page.branch | append '.md' %}
{% else %}
{% assign repo-branch = page.source %}
{% assign readme-file = page.source %}
{% assign repo-branch = page.source %}
{% assign readme-file = page.source | append '.md' %}
{% endif %}

{% assign readme-loc = page.file | default: 'README.md' %}
{% if page.file %}
{% if page.branch %}
{% assign readme-file = page.source | append: '-' | append: page.branch | append '/' | append page.file %}
{% assign repo-branch = page.source | append: '/tree/' | append: page.branch | append: page.file %}
{% else %}
{% assign readme-file = page.source | append '/' | append page.file %}
{% assign repo-branch = page.source | append: '/tree/' | append: 'master' | append: page.file %}
{% endif %}
{% endif %}

{% assign org = page.org | default: "strongloop" %}
<div class="alert alert-info" role="alert"><i class="fa fa-info-circle"></i>
<b>Note:</b> This page was generated from the
<a href="https://github.com/{{org}}/{{repo-branch}}">{{page.source}} README</a>.
<a href="https://github.com/{{org}}/{{repo-branch}}">{{page.source}} {{readme-loc}}</a>.
</div>

{{content}}

{% capture included-readme %}{% include_relative readmes/{{readme-file}}.md %}{% endcapture %}
{% capture included-readme %}{% include_relative readmes/{{readme-file}} %}{% endcapture %}
{{ included-readme | markdownify }}
{% else %}
<h3>ERROR: No source specified for README</h3>
Expand Down
3 changes: 2 additions & 1 deletion pages/en/lb4/Creating-decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ lang: en
title: 'Creating decorators'
keywords: LoopBack 4.0, LoopBack 4
layout: readme
source: metadata
source: loopback-next
file: packages/metadata/README.md
tags:
sidebar: lb4_sidebar
permalink: /doc/en/lb4/Creating-decorators.html
Expand Down
43 changes: 24 additions & 19 deletions update-v4-readmes.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
#!/bin/bash

# The following is a 5 column list of org, repo, branch, package, and file.
# - If the branch is NOT specified, then the README for that project
# will be pulled from npmjs.org instead and will reflect the latest
# release.
# The following is a 5 column list of org, repo, branch, file, and module.
# - If the module is specified, the README for that project will be
# pulled from npmjs.org instead and will reflect the latest release.
# For scoped packages such as `@loopback/metadata`, the `/` needs to
# be encoded as `%2f`. For example `@loopback%2fmetadata`.
# - If the branch IS specified, it will be used to fetch the README.md
# from the given github repo. If that branch is NOT master, then the
# branch name will be appended to the local readme file name.
#
# Examples:
# strongloop loopback-next master packages/metadata/README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will not work because we are not publishing loopback-next to npmjs.org. Unless I am missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only pull from npmjs if the module field (last one) is specified.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Could you please enhance the comments to explain what is each example showing?

# strongloop loopback-next master packages/metadata/README.md @loopback%2fmetadata
#
(cat <<LIST_END
strongloop loopback-next master metadata README.md
strongloop loopback-next master packages/metadata/README.md

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be altered to include all of the packages? It seems like we're only pointing at metadata with this setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For LB4, we only pull in README for metadata at this moment. This is the place you can add more readmes to be imported.

LIST_END
) | while read org repo branch package file; do
) | while read org repo branch file module; do
if [ -z "$file" ]; then
file="README.md"
fi
# Write the README.md to a file named after the repo
mkdir -p "pages/en/lb4/readmes"
DEST="pages/en/lb4/readmes/$package.md"
DEST="pages/en/lb4/readmes/$repo/$file"
if [ "$branch" != "master" ]; then
DEST="pages/en/lb4/readmes/$repo-$branch/$file"
fi
mkdir -p `dirname "$DEST"`
# When fetching from a branch of a gh repo
GHURL="https://raw.githubusercontent.com/$org/$repo/$branch/packages/$package/$file"
GHURL="https://raw.githubusercontent.com/$org/$repo/$branch/$file"
# When fetching from the latest release of a node module
NPMURL="https://registry.npmjs.org/@loopback/$package"
if [ -z "$branch" ]; then
NPMURL="https://registry.npmjs.org/$module"
if [ -n "$module" ]; then
# No branch means latest release, so fetch from npmjs.org
echo "fetching @loopback/$package from latest npmjs.org release..."
echo "fetching $module from latest npmjs.org release..."
echo $NPMURL
echo $DEST
curl -s $NPMURL | jq -r '.readme|rtrimstr("\n")' > $DEST
else
# The loopback-example-database repo contains a separate branch for each
# actual example project, so we need to add the branch name to the readme
# name.
if [ "$branch" != "master" ]; then
DEST="pages/en/lb4/readmes/$package-$branch.md"
fi
echo "fetching $org/$repo/$branch/packages/$package from GitHub's raw content domain..."
echo "fetching $org/$repo/$branch/$file from GitHub's raw content domain..."
curl -s $GHURL > $DEST
fi
done