Add providers folder

This commit is contained in:
Rodrigo Pombo 2019-02-16 15:49:10 -03:00
parent ef08d4ff1b
commit 09f0a59f86
3 changed files with 203 additions and 0 deletions

106
src/duotoneLight.js Normal file
View File

@ -0,0 +1,106 @@
// Duotone Light
// Author: Simurai, adapted from DuoTone themes for Atom (http://simurai.com/projects/2016/01/01/duotone-themes)
// Conversion: Bram de Haan (http://atelierbram.github.io/Base2Tone-prism/output/prism/prism-base2tone-evening-dark.css)
// Generated with Base16 Builder (https://github.com/base16-builder/base16-builder)
var theme /*: PrismTheme */ = {
plain: {
backgroundColor: "#faf8f5",
color: "#728fcb"
},
styles: [
{
types: ["comment", "prolog", "doctype", "cdata", "punctuation"],
style: {
color: "#b6ad9a"
}
},
{
types: ["namespace"],
style: {
opacity: 0.7
}
},
{
types: ["tag", "operator", "number"],
style: {
color: "#063289"
}
},
{
types: ["property", "function"],
style: {
color: "#b29762"
}
},
{
types: ["tag-id", "selector", "atrule-id"],
style: {
color: "#2d2006"
}
},
{
types: ["attr-name"],
style: {
color: "#896724"
}
},
{
types: [
"boolean",
"string",
"entity",
"url",
"attr-value",
"keyword",
"control",
"directive",
"unit",
"statement",
"regex",
"at-rule"
],
style: {
color: "#728fcb"
}
},
{
types: ["placeholder", "variable"],
style: {
color: "#93abdc"
}
},
{
types: ["deleted"],
style: {
textDecorationLine: "line-through"
}
},
{
types: ["inserted"],
style: {
textDecorationLine: "underline"
}
},
{
types: ["italic"],
style: {
fontStyle: "italic"
}
},
{
types: ["important", "bold"],
style: {
fontWeight: "bold"
}
},
{
types: ["important"],
style: {
color: "#896724"
}
}
]
};
module.exports = theme;

View File

@ -0,0 +1,88 @@
import netlify from "netlify-auth-providers";
import { Provider } from "./provider";
const TOKEN_KEY = "github-token";
function getHeaders() {
const token = window.localStorage.getItem(TOKEN_KEY);
return token ? { Authorization: `bearer ${token}` } : {};
}
async function getContent(repo, sha, path) {
const contentResponse = await fetch(
`https://api.github.com/repos/${repo}/contents${path}?ref=${sha}`,
{ headers: getHeaders() }
);
if (!contentResponse.ok) {
throw contentResponse;
}
const contentJson = await contentResponse.json();
const content = Base64.decode(contentJson.content);
return { content, url: contentJson.html_url };
}
const githubProvider: Provider = {
isLoggedIn: () => {
return !!window.localStorage.getItem(TOKEN_KEY);
},
logIn: () => {
return new Promise((resolve, reject) => {
const authenticator: any = new netlify({
site_id: "ccf3a0e2-ac06-4f37-9b17-df1dd41fb1a6"
});
authenticator.authenticate(
{ provider: "github", scope: "repo" },
(err, data) => {
if (err) {
reject(err);
}
window.localStorage.setItem(TOKEN_KEY, data.token);
resolve(data);
}
);
});
},
getCommits: async (path, repo, sha) => {
const commitsResponse = await fetch(
`https://api.github.com/repos/${repo}/commits?sha=${sha}&path=${path}`,
{ headers: getHeaders() }
);
if (!commitsResponse.ok) {
throw commitsResponse;
}
const commitsJson = await commitsResponse.json();
const commits = commitsJson
.slice(0, top)
.map(commit => ({
sha: commit.sha,
date: new Date(commit.commit.author.date),
author: {
login: commit.author
? commit.author.login
: commit.commit.author.name,
avatar: commit.author
? commit.author.avatar_url
: "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
},
commitUrl: commit.html_url,
message: commit.commit.message
}))
.sort(function(a, b) {
return a.date - b.date;
});
await Promise.all(
commits.map(async commit => {
const info = await getContent(repo, commit.sha, path);
commit.content = info.content;
commit.fileUrl = info.url;
})
);
return commits;
}
};
export default githubProvider;

View File

@ -0,0 +1,9 @@
type Commit = {
message: string;
};
export interface Provider {
isLoggedIn?: () => boolean;
logIn?: () => Promise<null>;
getCommits: (path: string, repo?: string, sha?: string) => Promise<Commit[]>;
}