The two functions for creating a frontend.Package, legacyCreatePackage
and createPackageNew, are merged into a single createPackage function.
createPackage uses the new PackageMeta type, as input. It does not take
any legacy structs as input and returns a frontend.Package.
In future CLs, PackageMeta will be used to LegacyDirectory, when
fetching data for the directories tab.
For golang/go#39629
Change-Id: I80ec5272c6f8e237f0752938a89c633e3a1b81f5
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/241441
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Begin using github.com/google/safehtml for frontend templates.
The safehtml module replaces html/template to provide more secure
template execution.
- Templates must come from constant strings or trusted sources.
This CL constructs TrustedSource values from the filesystem
paths that we use.
- Injected HTML must be constructed from known safe values. This CL
does this in some places. In others, notably the documentation, it
uses an escape hatch that we will close in a future CL.
- Identifiers must be constructed safely. We temporarily use an
escape hatch for license identifiers.
- There is a gotcha when using safehtml types: values that
resolve to the empty string do not evaluate to false in the
context of an `if`. We have to replace `.X` inside an `if`
with `.X.String` when `.X` is a `safehtml.HTML` or the like.
Still to be done:
- Remove all `legacyconversions.RiskilyXXX` calls (https://golang.org/issue/39960).
- Remove `template.HTML` from internal/fetch/dochtml (https://golang.org/issue/39959).
Change-Id: Icf4793d70cb2441ba30abd4e7394c4696be64a7b
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/240499
Reviewed-by: Julie Qiu <julie@golang.org>
Instead of generating the entire breadcrumb HTML in code, put the
static bits in details.tmpl and build the dynamic data in code.
This is not only easier to read and maintain, but it also removes
some uses of template.HTML, which we're trying to eliminate.
Change-Id: Ic2868b88d15496bbe4bccff6abb82481e7358b7d
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/240437
Reviewed-by: Julie Qiu <julie@golang.org>
Functions that are used only by the legacy data model are renamed with the prefix legacy.
This includes:
* createPackage
* createDirectory
* servePackagePage
* serveModulePage
* serveDirectoryPage
Change-Id: I72071f56df7e79dfbf27355479d29bad4ad19a38
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/238097
Reviewed-by: Jonathan Amsterdam <jba@google.com>
ModuleInfo is added, which represents the module info for the new data
model. ModuleInfo is embedded in LegacyModuleInfo.
In order to support the existing overview tab functionality,
GetDirectoryNew was changed to return the module README, regardless of
whether there is a README for the directory.
We will change this logic to display the README for the directory in a
future CL.
Change-Id: I624a6d99b711870826fd7dff9100d4ad47852db2
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/766801
Reviewed-by: Jonathan Amsterdam <jba@google.com>
ModuleInfo is renamed to LegacyModuleInfo, as a step towards
deprecating LegacyReadmeFilePath and LegacyReadmeContents.
In a follow up CL, we will add ModuleInfo as an embedded struct
to LegacyModuleInfo.
Change-Id: Ie452420448eec1d13edaf62e548df0b9e2cbbe4b
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/766479
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
The following structs have been renamed with a Legacy prefix:
* internal.Directory
* internal.Package
* internal.VersionedPackage
* sample.Package
The following fields on internal.ModuleInfo have also been changed:
* ReadmeFilePath
* ReadmeFileContents
This is done to help us distinguish between legacy and method
structs/methods while migrating code to the new data model.
Change-Id: Ibedf71d4db6323ef5aa05d73a0240537ea6073d3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/765160
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
- Redo the arguments to Package so it can derive the Name
and V1Path fields from them.
- Add a list of suffixes to the arguments of Module.
Change-Id: I966197846b49befceb04779c9a04162957fbeb87
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/733603
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
This is the first step towards making sample clearer and less
error-prone.
- Rename Module and Package to DefaultModule and DefaultPackage, so
existing code continues to work. In later CLs, I'll replace most or
all calls to these functions.
- Define ModuleInfo, Module and Package to take as arguments the most
common fields. The Module function does _not_ create a package; it
returns a module with no packages.
- Most important: define AddPackage, which adds a Package to a Module
and correctly updates Module.Directories.
- Remove VersionedPackage, since it's clearer to create one directly.
- Update a couple of call sites, just to get tests to pass. More
updates in a later CL.
Change-Id: I46eb94ba897d4f122483b58435107b8782c6044f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/733619
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
golang.org/x/discovery is renamed to golang.org/x/pkgsite.
When the repository is open sourced, it will be hosted at
go.googlesource.com/pkgsite.
Change-Id: Ifc3b45b771a385b99179e785447f2a87afcacf87
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/724273
Reviewed-by: Jonathan Amsterdam <jba@google.com>
This CL is pure renaming:
- internal.VersionInfo to internal.ModuleInfo
- related variables from vi to mi
Updates b/150143758.
Change-Id: I5da63a07d6f9b731016ffe92e403e5f2d9aadab7
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/673875
Reviewed-by: Julie Qiu <julieqiu@google.com>
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
To be in accordance with golang.org/wiki/CSSStyleGuide
While not noted in the CSS style guide, using the ID attribute should
only be used when a class won’t suffice (linking to a place in the page,
label “for” attribute values, etc.). Otherwise it ends up on the window
object, polluting the global namespace.
Change-Id: Ibc4954d72455b89cc284d5baa87711c9333b83fb
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/672138
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
The same can be achieved with CSS selectors, using :nth-child
and :nth-of-type.
Change-Id: I57486922d5d0060862b20d67f56be808b6c65082
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/617945
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
When rendering a details page, the Header field can be either a Module,
Directory, or Package, and in our templates we rely on fields having
consistent meaning.
Renaming Module.Path to Module.ModulePath makes this simpler: we can
just refer to $header.ModulePath regardless of which namespace we're in.
Updates b/143814014
Change-Id: I0e3542244467af70a4ea45b43836eef8a0a52a24
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/613504
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
Put the link in the latest-version badge in the form
mod@version/suffix.
The best way to do this was to move the latest-badge-link
logic from the template to the server itself.
Also, rename the Suffix field of Package to PathAfterDirectory
to more accurately describe it.
Fixes b/144681389.
Change-Id: I16a78224ee6fa53b60954716338347a298dbef21
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/604414
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
The Package.Suffix value built in createPackage is never used. Only
directories display the suffix, and the Suffix field is set in
createDirectory.
Change-Id: Icd8921f6303775079f8e15d77e34346b6019c869
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/604413
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Avoid the use of the naked term "version" in the details
header. Instead, we have:
- DisplayVersion: the version formatted for human readability.
- LinkVersion: the version to use in links to the discovery site.
Also, use the link version in nav tab links:
Fixes b/144873325.
And improve test coverage.
Change-Id: Ida80867b6bd70a32c18f45b21b0b361b9e8e904f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/603789
Reviewed-by: Robert Findley <rfindley@google.com>
We were using the formatted version as one input to our latest-version
check, and comparing it with the linkable version. That fails with
pseudoversions.
Use the linkable version in both cases.
Fixes b/144860268.
Change-Id: I0f4c82dbec42863378e5d649bbbe5ebe99de8b53
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/602829
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Move the html-checking code from internal/frontend tests to its own package.
Ths is a first step towards making these structural tests usable elsewhere,
like in an integration test that runs against a live endpoint.
Since these are now exported, give them better names in some cases.
Also, generalize to use regexps where that makes sense.
Change-Id: I1a3e0c09954d9cb07200c087db17e499a9d0d9a7
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/599089
Reviewed-by: Julie Qiu <julieqiu@google.com>
Put all test-related packages there (sample, testhelper, integration).
production risk: none
Change-Id: I06673aaa5c3fd6966410f1c1ad2b34e4f2d88f94
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/599080
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
- Fix the position of the latest-version badge.
- Fix the height of the DetailsHeader-title div.
- Inline the copy icon.
Also, rewrote the breadcrumb test to use
the new html-scraping stuff, to make it less brittle.
Tested:
- Using "Slow 3G" mode in Chrome.
- I made Heschi look at it and he said it's fine.
Change-Id: I3706a6e59e70c7094a2c7fd1d210dabf01a51cb3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/597501
Reviewed-by: Alexander Rakoczy <rakoczy@google.com>
The URL logic is updated so that when a user requests a
package/module/directory with /<path> and do not specify a version, the
links to the tabs also follow the /path?tab=<tab> scheme.
The only exception to this is packages on the directories tab, because
(1) it required more extensive refactoring and (2) the latest version of
a package might not be part of the same module, so deep linking seemed
preferable.
Change-Id: I7bc92076ccb59b933c752377dd764128290228c4
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/592720
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Change the visual appearance of our image buttons when the
cursor hovers over them, and clicks on them.
We have two buttons that are images: the search magnifying glass,
and the copy-path button.
- Give them both the "ImageButton" class.
- Add css rules for .ImageButton that change the background
based on the state.
- Round the bounding box of the button to look nice.
Fixes b/143613876.
Change-Id: If90d603f12b84ef1c13a3690910ff91e59b4f80a
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/589895
Reviewed-by: Alexander Rakoczy <rakoczy@google.com>
In some browsers (e.g. Firefox), clicking the copy
button would cause the page to jump. This was because the hidden
input element gained focus, and firefox wants to jump to the focus.
Releasing focus (AFTER the copy, as I learned the hard way) fixed it.
Fixes b/143613723.
Change-Id: I47c9ae322514d381824f9d787f463243483396b6
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/589179
Reviewed-by: Alexander Rakoczy <rakoczy@google.com>
The hidden element I introduced for import path copying was appearing
in the tab order.
I took it out of the tab order by giving it a tabindex attribute of -1.
Fixes b/143376521.
Change-Id: Iac64544e70aeaefcaf787c425ae64a2cc3cb697f
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/586895
Reviewed-by: Alexander Rakoczy <rakoczy@google.com>
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Make the copy-import-path button into a proper button. This makes it
part of the tab order, correctly highlights it when it has focus, and
makes the special keypress event handlers unnecessary.
The only way I could get the icon to display in medium turquoise was
to set the fill directly on the svg element (and remove overriding
fill attributes on sub-elements).
Change-Id: I3c16a4f99a6b7d41ad8df096de02680090c1a16d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/584335
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Alexander Rakoczy <rakoczy@google.com>
Add a "copy" icon next to our breadcrumb path that lets
the user copy the package or module path to the clipboard.
This supports:
- Pasting a package path into a Go import declaration;
- Pasting a module path into a go.mod file.
The appearance is based on the mock
Complicated by the case where the module is the standard library itself;
then there's nothing to copy, so we don't show the icon.
Change-Id: I3827424a105ea4fa9e941d3e56b5424451b19f23
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/579359
Reviewed-by: Alexander Rakoczy <rakoczy@google.com>
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
The source code link is removed from the package/module header. It
will be moved to the Overview (currently README) tab in a later CL.
Updates b/139529503
Change-Id: I6084d72dafae37371b0b09ab329ffbfd28d3ce07
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/571343
Reviewed-by: Jonathan Amsterdam <jba@google.com>
details.go is split into the following files:
* handlers.go: contains handlers for /pkg and /mod
* header.go: contains code for creating a module or pkg header
* tabs.go: contains logic for routing tabs
Tests are also moved to the corresponding *_test.go files.
Change-Id: Ia0268e4a0cd61667cb63a9a2bc205147e4f7f194
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/567698
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>