-
Notifications
You must be signed in to change notification settings - Fork 5
Adding a New Parser
The first thing to do is define the basic SourceSite:
- Create
MiniIndex.Models/SourceSites/<SiteName>Source.cs
- Copy basics from another SourceSite (I recommend Cults3d).
- Change the naming to match your SourceSite.
- Update
BaseUri
to the URL relative to the Creator's page, for examplehttps://www.myminifactory.com/users/
is theBaseUri
forhttps://www.myminifactory.com/users/Evocatus%20miniature
The actual parser is the main thing to focus on getting right. You can refer to the existing parsers in MiniIndex.Core/Minis/Parsers/
for references on what a parser does, they're all fairly simple. Most websites don't have an API, so we use HTMLAgilityPack to parse the actual HTML.
- Creator URL - The URL of the profile of the person who uploaded/created the Mini
- Creator Name - The username of the creator.
- Mini Name - The name/title of the Mini.
- Thumbnail URL - The URL for a picture of the Mini.
- Link - The URL to the Mini.
- Cost - The cost of the Mini (0 for free).
TODO - Reach out to us if you want to parse a website using it's API and we'll fill this in together :). Right now we only do this for Thingiverse, and it's a bit more involved with "ownership" of API keys and rate limiting.
Look through the existing HTML Parsers for references to how to do this right. Things like Thumbnail and Mini name can likely be parsed easily from meta tags like og:image
that are generally well-used for social media websites. Others might be a bit harder and can be done by looking at various header tags or if you're lucky have the ID field used.
- Create the parser file -
MiniIndex.Core/Minis/Parsers/<SiteName>/<SiteName>Parser.cs
- Implement
CanParse
- CanParse parses the URL to determine if this parser should parse it. It should do everything possible to ensure that the given URL is a valid model, and not a user, profile, or other page. - Implement
ParseFromUrl
- This manually parses through the HTML of the website to make aCreator
object and returns aMini
object. - Parse
Creator
information - In the previous step you defined the structure of the URL and you'll declare your creator here based off the URL and creator name. - Parse the
Mini
information -
Every SourceSite much be instantiated in MiniIndex.Persistence/Configuration/SourceSiteEntityConfiguration.cs
, simply add .HasValue<Cults3dSource>("<SiteName>")
Styling for each site individually is done in MiniIndex/wwwroot/css/site.css
, follow the outline below, trying to use the site's primary color for the button background. Make sure your PNG has transparency and isn't massive.
.thumb-wrapper.<SiteName> span {
`background: transparent url('../images/SourceSiteIcons/<SiteName>.png') no-repeat;
}
.<SiteName> {
background-color: #<Site's primary color> !important;
border-color: #<Site's primary color> !important;
color: <white or black depending on background> !important;
}
Make sure you do basic testing:
- Free Minis parse properly and show up when the "Free Only" checkbox is used.
- Paid Minis parse properly and don't show up when the "Free Only" checkbox is used.
- The link to the Mini works.
- The link on the Creator's page to their profile works.
- Names with potentially special characters like & or " parse properly.
- The icon on the browse pages looks good.
- The coloring of the button is good and has good contrast with the text.