Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Commit

Permalink
add: ver 1.6 parse GitHub user info via JSONP.
Browse files Browse the repository at this point in the history
  • Loading branch information
Innei committed Jun 27, 2019
1 parent 8210175 commit 431c6f8
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 54 deletions.
58 changes: 58 additions & 0 deletions page-opensource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php
/**
* 开源页面
*
* @author innei
* @package custom
*/
$this->need('header.php');
require_once 'pages.php';
?>
<main style="overflow:hidden">
<nav class="navigation">
<a href="<?php echo $GLOBALS['project'] ?>">精选</a>
<a href="<?php echo $GLOBALS['opensource'] ?>" class="active">开源</a>
</nav>
<div id="loading" class="jsonp-loading">
<div class="box"></div>
</div>
<div id="opensource-wrap" style="opacity: 0">
<section class="me github">
<div class="my-avatar">
<img src="">
</div>
<div class="my-info">
<h1><span></span>
<svg width="100%" height="3.5rem">
<text text-anchor="start" x="0" y="2.2rem" class="text text-1">
</text>
<text text-anchor="start" x="0" y="2.2rem" class="text text-2">
</text>
<text text-anchor="start" x="0" y="2.2rem" class="text text-3">
</text>
<text text-anchor="start" x="0" y="2.2rem" class="text text-4">
</text>
</svg>
</h1>
<p></p>
<div class="social-icons">
</div>
</section>
<section class="repos" style="overflow:hidden">
<div class="repo-wrap">
<ul id="repo-list">
<li></li>
</ul>
</div>
</section>
</div>
<?php if ($this->options->github_username): ?>
<script>
window.githubID = "<?php $this->options->github_username(); ?>"
</script>
<script src="<?php $this->options->themeUrl("src/github.js") ?>"></script>
<?php endif;?>
</main>

<?php $this->need('footer.php') ?>
57 changes: 27 additions & 30 deletions page-works.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,39 @@
$projects_text = $this->text;
$projects_json = json_decode($projects_text, true);
?>


<main>
<nav class="navigation">
<a href="<?php $GLOBALS['project'] ?>" class="active">精选</a>
<!-- <a href="/project/web">网站</a>
<a href="/project/music">音乐</a>-->
</nav>
<section class="page">
<section class="project-list">
<div class="row multi">
<?php foreach ($GLOBALS['stack'] as $work) {
if ($work['template'] == 'page-works_info.php'):
// 解析介绍页 JSON 格式
$JSON = json_decode($work['text'], true);
$img = $JSON['project_img'] ? $JSON['project_img'] : $this->options->themeUrl . '/src/img/Kico.jpg';
echo '<div class="col-4 col-s-3 col-m-2">
<main>
<nav class="navigation">
<a href="<?php echo $GLOBALS['project'] ?>" class="active">精选</a>
<a href="<?php echo $GLOBALS['opensource'] ?>">开源</a>
</nav>
<section class="page">
<section class="project-list">
<div class="row multi">
<?php foreach ($GLOBALS['stack'] as $work) {
if ($work['template'] == 'page-works_info.php') :
// 解析介绍页 JSON 格式
$JSON = json_decode($work['text'], true);
$img = $JSON['project_img'] ? $JSON['project_img'] : $this->options->themeUrl . '/src/img/Kico.jpg';
echo '<div class="col-4 col-s-3 col-m-2">
<a href="' . $work['permalink'] . '">
<img src="' . $img . '">
<h4>' . $work['title'] . '</h4>
</a>
</div>';
endif;
} ?>
endif;
} ?>

<?php foreach ($projects_json as $key => $value): ?>
<div class="col-4 col-s-3 col-m-2">
<a href="<?php echo $value['url'] ?>">
<img src="<?php $value['img'] ? print_r($value['img']) : $this->options->themeUrl('src/img/Kico.jpg') ?>?>">
<h4><?php echo $value['name'] ?></h4>
</a>
</div>
<?php endforeach; ?>
</div>
</section>
<?php foreach ($projects_json as $key => $value) : ?>
<div class="col-4 col-s-3 col-m-2">
<a href="<?php echo $value['url'] ?>">
<img src="<?php $value['img'] ? print_r($value['img']) : $this->options->themeUrl('src/img/Kico.jpg') ?>?>">
<h4><?php echo $value['name'] ?></h4>
</a>
</div>
<?php endforeach; ?>
</div>
</section>
</main>
</section>
</main>

<?php $this->need('footer.php') ?>
18 changes: 10 additions & 8 deletions pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<?php $this->widget('Widget_Contents_Page_List')->to($pages);
$works = $index_pages = $collection = array();
while ($pages->next()):
switch ($pages->template):
case 'page-note.php':
switch ($pages->template): case 'page-note.php':
$GLOBALS['note'] = $pages->permalink;
break;
case 'page-works.php':
Expand All @@ -25,12 +24,15 @@
case 'page-index.php':
$index_pages[] = $pages->permalink;
break;
case 'page-link.php':
$GLOBALS['link'] = $pages->permalink;
break;
case 'page-archive.php':
$GLOBALS['archive'] = $pages->permalink;
break;
case 'page-link.php':
$GLOBALS['link'] = $pages->permalink;
break;
case 'page-archive.php':
$GLOBALS['archive'] = $pages->permalink;
break;
case 'page-opensource.php':
$GLOBALS['opensource'] = $pages->permalink;
break;
endswitch;
endwhile;
$GLOBALS['works'] = $works;
Expand Down
51 changes: 51 additions & 0 deletions src/github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var githubInfo = document.createElement("script");
var githubRepos = document.createElement("script");
function select(dom) {
return document.querySelectorAll(dom).length == 1
? document.querySelector(dom)
: document.querySelectorAll(dom);
}

function userInfo(res) {
select(".my-avatar > img").setAttribute("src", res.data.avatar_url);
select(".my-info span").innerText = res.data.login;
[...select(".my-info text")].forEach(
item => (item.innerHTML = res.data.login)
);
select(".my-info p").innerText = res.data.bio;
select(".social-icons").innerHTML = `<a href="https://github.com/${
res.data.login
}" target="_blank"
ks-tag="bottom"
ks-text="GitHub"><i
class="fa fa-github" style="color: #44006f"></i></a>`;
}

function userRepos(res) {
let content = "";
for (let item of res.data) {
content += `<li> <a href="${item.html_url}" target
="_blank"><div class="repo-name">${
item.full_name
}</div> </a><div class="repo-des">${
item.description ? item.description : ""
}</div></li>`;
}
select("#repo-list").innerHTML = content;
loadingComplete();
}
function loadingComplete() {
select("#loading.jsonp-loading").remove();
select("#opensource-wrap").removeAttribute("style");
}

githubInfo.src = `https://api.github.com/users/${
window.githubID
}?callback=userInfo`;

document.head.appendChild(githubInfo);

githubRepos.src = `https://api.github.com/users/${
window.githubID
}/repos?sort=updated&callback=userRepos`;
document.head.appendChild(githubRepos);
Loading

0 comments on commit 431c6f8

Please sign in to comment.