Skip to content

Commit

Permalink
add examples to homepage and readme + small bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
g-harel committed Jun 7, 2019
1 parent f352c0b commit 8e47edb
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 7 deletions.
55 changes: 55 additions & 0 deletions README.md
Expand Up @@ -40,6 +40,17 @@ _When viewing a package on npm, it is conveniently accessible with a one-char ed
+ https://www.npmfs.com/package/<name>
```

<details>
<summary>Examples</summary>
<a href="https://npmfs.com/lodash">https://npmfs.com/lodash</a>
<br>
<a href="https://npmfs.com/package/lodash">https://npmfs.com/package/lodash</a>
<br>
<a href="https://npmfs.com/request">https://npmfs.com/request</a>
<br>
<a href="https://npmfs.com/package/request">https://npmfs.com/package/request</a>
</details>

##

Specific package versions can be accessed directly.
Expand All @@ -48,6 +59,17 @@ Specific package versions can be accessed directly.
https://npmfs.com/package/<name>/<version>
```

<details>
<summary>Examples</summary>
<a href="https://npmfs.com/package/chalk/2.4.2">https://npmfs.com/package/chalk/2.4.2</a>
<br>
<a href="https://npmfs.com/package/chalk/1.0.0">https://npmfs.com/package/chalk/1.0.0</a>
<br>
<a href="https://npmfs.com/package/commander/2.20.0">https://npmfs.com/package/commander/2.20.0</a>
<br>
<a href="https://npmfs.com/package/commander/1.0.0">https://npmfs.com/package/commander/1.0.0</a>
</details>

##

Directories and files inside the package are viewed by appending the path.
Expand All @@ -58,6 +80,17 @@ https://npmfs.com/package/<name>/<version>/example/
https://npmfs.com/package/<name>/<version>/example/index.js
```

<details>
<summary>Examples</summary>
<a href="https://npmfs.com/package/async/3.0.1/internal/">https://npmfs.com/package/async/3.0.1/internal/</a>
<br>
<a href="https://npmfs.com/package/async/3.0.1/internal/once.js">https://npmfs.com/package/async/3.0.1/internal/once.js</a>
<br>
<a href="https://npmfs.com/package/react/16.8.6/umd/">https://npmfs.com/package/react/16.8.6/umd/</a>
<br>
<a href="https://npmfs.com/package/react/16.8.6/package.json">https://npmfs.com/package/react/16.8.6/package.json</a>
</details>

##

Package versions are compared (`version-0 .. version-1`) by navigating to the root directory of `version-0`, clicking on the `diff` link in the top right, and selecting `version-1` in the version list.
Expand All @@ -68,6 +101,17 @@ https://npmfs.com/compare/<name>/<version-0>/<version-1>

In this compare view, line numbers are a shortcut to their respective file's source.

<details>
<summary>Examples</summary>
<a href="https://npmfs.com/compare/debug/4.1.0/4.1.1">https://npmfs.com/compare/debug/4.1.0/4.1.1</a>
<br>
<a href="https://npmfs.com/compare/debug/3.0.0/4.0.0">https://npmfs.com/compare/debug/3.0.0/4.0.0</a>
<br>
<a href="https://npmfs.com/compare/underscore/1.9.0/1.9.1">https://npmfs.com/compare/underscore/1.9.0/1.9.1</a>
<br>
<a href="https://npmfs.com/compare/underscore/1.6.0/1.7.0">https://npmfs.com/compare/underscore/1.6.0/1.7.0</a>
</details>

##

Deep links are found on the right side of lines in both the file and diff views. These links will add a hash to the url which scrolls the browser to the selected line, and highlights it.
Expand All @@ -77,6 +121,17 @@ https://npmfs.com/package/<name>/<version>/index.js#<line>
https://npmfs.com/compare/<name>/<version-0>/<version-1>#<line>
```

<details>
<summary>Examples</summary>
<a href="https://npmfs.com/package/bluebird/3.5.5/js/release/race.js#L32">https://npmfs.com/package/bluebird/3.5.5/js/release/race.js#L32</a>
<br>
<a href="https://npmfs.com/compare/bluebird/3.5.4/3.5.5#D0L35">https://npmfs.com/compare/bluebird/3.5.4/3.5.5#D0L35</a>
<br>
<a href="https://npmfs.com/package/moment/2.24.0/locale/ca.js#L81">https://npmfs.com/package/moment/2.24.0/locale/ca.js#L81</a>
<br>
<a href="https://npmfs.com/compare/moment/2.23.0/2.24.0#D19L0">https://npmfs.com/compare/moment/2.23.0/2.24.0#D19L0</a>
</details>

##

The sticky header sections often contain useful links to navigate between pages.
Expand Down
4 changes: 0 additions & 4 deletions internal/diff/patch.go
Expand Up @@ -46,8 +46,6 @@ func patchParse(out string) ([]*Patch, error) {
if strings.HasPrefix(line, "---") {
if strings.HasPrefix(line, "--- a/content/") {
patch.PathA = strings.TrimPrefix(line, "--- a/content/")
} else {
patch.PathA = ""
}
continue
}
Expand All @@ -56,8 +54,6 @@ func patchParse(out string) ([]*Patch, error) {
if strings.HasPrefix(line, "+++") {
if strings.HasPrefix(line, "+++ b/content/") {
patch.PathB = strings.TrimPrefix(line, "+++ b/content/")
} else {
patch.PathB = ""
}
continue
}
Expand Down
8 changes: 5 additions & 3 deletions internal/tarball/extract.go
Expand Up @@ -27,9 +27,11 @@ func Extract(source io.Reader, handler ExtractHandler) error {
return fmt.Errorf("advance to next file: %v", err)
}

err = handler(header.Name, tarball)
if err != nil {
return fmt.Errorf("handler error: %v", err)
if !header.FileInfo().IsDir() {
err = handler(header.Name, tarball)
if err != nil {
return fmt.Errorf("handler error: %v", err)
}
}
}

Expand Down
71 changes: 71 additions & 0 deletions templates/pages/home.html
Expand Up @@ -33,6 +33,7 @@
border: 1px solid #d7d7d7;
padding: 1rem;
white-space: pre-line;
word-break: break-word;
}

.wrapper pre .red {
Expand All @@ -53,6 +54,26 @@
.wrapper h2, .wrapper hr {
margin: 2rem 0;
}

.wrapper details summary {
cursor: pointer;
padding: 0.25rem 0 0;
}

.wrapper details[open] summary {
margin-bottom: 0.25rem;
}

.wrapper details a {
display: inline-block;
margin: 0.25rem;
padding: 0.25rem 0 0 1rem;
text-decoration: underline;
}

.wrapper details + hr {
margin-top: 1.5rem;
}
</style>
{{- end -}}

Expand Down Expand Up @@ -93,12 +114,32 @@ <h2>Usage</h2>
<span class="red">&nbsp;https://www.npm<i>j</i>s.com/package/&lt;name&gt;</span>
<span class="green">&nbsp;https://www.npm<i>f</i>s.com/package/&lt;name&gt;</span>
</pre>
<details>
<summary>Examples</summary>
<a href="https://npmfs.com/lodash">https://npmfs.com/lodash</a>
<br>
<a href="https://npmfs.com/package/lodash">https://npmfs.com/package/lodash</a>
<br>
<a href="https://npmfs.com/request">https://npmfs.com/request</a>
<br>
<a href="https://npmfs.com/package/request">https://npmfs.com/package/request</a>
</details>
<hr>

<p>Specific package versions can be accessed directly.</p>
<pre>
https://npmfs.com/package/&lt;name&gt;/&lt;version&gt;
</pre>
<details>
<summary>Examples</summary>
<a href="https://npmfs.com/package/chalk/2.4.2">https://npmfs.com/package/chalk/2.4.2</a>
<br>
<a href="https://npmfs.com/package/chalk/1.0.0">https://npmfs.com/package/chalk/1.0.0</a>
<br>
<a href="https://npmfs.com/package/commander/2.20.0">https://npmfs.com/package/commander/2.20.0</a>
<br>
<a href="https://npmfs.com/package/commander/1.0.0">https://npmfs.com/package/commander/1.0.0</a>
</details>
<hr>

<p>Directories and files inside the package are viewed by appending the path.</p>
Expand All @@ -107,20 +148,50 @@ <h2>Usage</h2>
https://npmfs.com/package/&lt;name&gt;/&lt;version&gt;/example/
https://npmfs.com/package/&lt;name&gt;/&lt;version&gt;/example/index.js
</pre>
<details>
<summary>Examples</summary>
<a href="https://npmfs.com/package/async/3.0.1/internal/">https://npmfs.com/package/async/3.0.1/internal/</a>
<br>
<a href="https://npmfs.com/package/async/3.0.1/internal/once.js">https://npmfs.com/package/async/3.0.1/internal/once.js</a>
<br>
<a href="https://npmfs.com/package/react/16.8.6/umd/">https://npmfs.com/package/react/16.8.6/umd/</a>
<br>
<a href="https://npmfs.com/package/react/16.8.6/package.json">https://npmfs.com/package/react/16.8.6/package.json</a>
</details>
<hr>

<p>Package versions are compared (<code>version-0 .. version-1</code>) by navigating to the root directory of <code>version-0</code>, clicking on the <code>diff</code> link in the top right, and selecting <code>version-1</code> in the version list.</p>
<pre>
https://npmfs.com/compare/&lt;name&gt;/&lt;version-0&gt;/&lt;version-1&gt;
</pre>
<p>In this compare view, line numbers are a shortcut to their respective file's source.</p>
<details>
<summary>Examples</summary>
<a href="https://npmfs.com/compare/debug/4.1.0/4.1.1">https://npmfs.com/compare/debug/4.1.0/4.1.1</a>
<br>
<a href="https://npmfs.com/compare/debug/3.0.0/4.0.0">https://npmfs.com/compare/debug/3.0.0/4.0.0</a>
<br>
<a href="https://npmfs.com/compare/underscore/1.9.0/1.9.1">https://npmfs.com/compare/underscore/1.9.0/1.9.1</a>
<br>
<a href="https://npmfs.com/compare/underscore/1.6.0/1.7.0">https://npmfs.com/compare/underscore/1.6.0/1.7.0</a>
</details>
<hr>

<p>Deep links are found on the right side of lines in both the file and diff views. These links will add a hash to the url which scrolls the browser to the selected line, and highlights it.</p>
<pre>
https://npmfs.com/package/&lt;name&gt;/&lt;version&gt;/index.js#&lt;line&gt;
https://npmfs.com/compare/&lt;name&gt;/&lt;version-0&gt;/&lt;version-1&gt;#&lt;line&gt;
</pre>
<details>
<summary>Examples</summary>
<a href="https://npmfs.com/package/bluebird/3.5.5/js/release/race.js#L32">https://npmfs.com/package/bluebird/3.5.5/js/release/race.js#L32</a>
<br>
<a href="https://npmfs.com/compare/bluebird/3.5.4/3.5.5#D0L35">https://npmfs.com/compare/bluebird/3.5.4/3.5.5#D0L35</a>
<br>
<a href="https://npmfs.com/package/moment/2.24.0/locale/ca.js#L81">https://npmfs.com/package/moment/2.24.0/locale/ca.js#L81</a>
<br>
<a href="https://npmfs.com/compare/moment/2.23.0/2.24.0#D19L0">https://npmfs.com/compare/moment/2.23.0/2.24.0#D19L0</a>
</details>
<hr>

<p>The sticky header sections often contain useful links to navigate between pages.</p>
Expand Down

0 comments on commit 8e47edb

Please sign in to comment.