首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何订购/sites的结果是一个用户友好的方式使用它在我们的应用程序。

如何订购/sites的结果是一个用户友好的方式使用它在我们的应用程序。
EN

Stack Apps用户
提问于 2010-07-24 15:45:11
回答 3查看 173关注 0票数 3

自从订购/sites 没有保证以来,我如何有效地以用户友好的方式订购网站?

一般要求:

  1. 三部曲必须保持在stackoverflow.com,meta.stackoverflow.com,serverfault.com,meta.serverfault.com,superuser.com,meta.superuser.com。排行榜的首位
  2. StackApps应该保持在名单的底部或略低于三部曲。.,堆栈或..meta.superuser.com,stackapps,.
  3. 新的beta堆栈交换站点必须与它们的元站点一起分组。,webapps.stackexchange.com,meta.webapps.stackexchange.com,gaming.stackexchange.com,meta.stackexchange.com,.
  4. 官方的堆栈交换站点(beta之外)应该在三部曲下面进行比较。

有什么想法,想法,暗示吗?

EN

回答 3

Stack Apps用户

回答已采纳

发布于 2010-07-25 09:21:16

以下是我对凯文使用Soapi.JS的分类的看法

  • 从stackauth /sites获取站点列表
  • 从每个站点获取社区用户以获取创建日期
  • 将每个元连接到它的父级
  • 按日期排序
  • 按“状态”或类型分组。
  • 呈现成组或作为一个列表呈现。

现场演示

附注:-我将收紧这段代码,并将其合并到Soapi.JS中,供那些使用它的人使用。

丙氨酸氨基转移酶(alt文本文本)

代码语言:javascript
复制
/* 
This is the money shot
*/

// get a list of sites from stackauth
Soapi.RouteFactory("", apiKey).Sites()
.getResponse(function(sitesResponse) {

    // count down so we know when we are done
    var count = sitesResponse.items.length;

    // determine the increment of the progress bar for each operation
    progressStep = document.getElementById("progressOuter").clientWidth / count;


    function checkCount() {

        stepProgress();
        if (--count == 0) {
            // all sites reported in

            // perform meta assocations

            while (sitesResponse.items.length > 0) {

                // take the site of the bottom
                var item = sitesResponse.items.shift();

                // if it is not a meta site, add it to the site list
                // cannot depend on linked_meta right not
                if (item.api_endpoint.toLowerCase().indexOf(".meta.") == -1) {
                    sites.push(item);
                }
                else {
                    // check the site list to see if the parent has been seen yet
                    var parent = sites.tryGetParentByEndpoint(item.api_endpoint);
                    if (parent) {
                        // attach the meta to the parent
                        parent.linked_meta = item;
                    }
                    else {
                        // parent not seen yet, stick it back on top
                        sitesResponse.items.push(item);
                    };
                };
            };

            // do sorting and arrangement

            // now we have a list of sites similar to this
            // stackoverflow.com
            //    meta.stackoverflow.com
            // stackapps.com
            // gaming.stackexchange.com
            //    meta.gaming.stackexchange.com


            // lets sort by date
            sites = sites.sort(function(a, b) {
                return a.creation_date - b.creation_date;
            });

            // and segregate the sites by state as we 
            sites.normal = [];
            sites.open_beta = [];
            sites.closed_beta = [];
            sites.linked_meta = [];

            // empty the array
            var tmp = sites.splice(0, sites.length);

            // and push them in order of appearance to maintain date sort
            // into both the parent array and the group arrays
            while (tmp.length > 0) {
                var site = tmp.shift();
                sites.push(site);
                sites[site.state].push(site);
                if (site.linked_meta) {
                    sites.linked_meta.push(site.linked_meta);
                };
            };

            progressComplete();
            // return results
            callback(sites);
        };
    };


    // get community user from each site to get creation date

    for (var i = 0; i < sitesResponse.items.length; i++) {

        var site = sitesResponse.items[i];

        Soapi.RouteFactory(site.api_endpoint, apiKey)
        .UsersById(-1).getResponse(function(usersResponse, context) {

            // add the date to the site so we can sort
            context.creation_date = usersResponse.items[0].creation_date;
            checkCount();
        }, function(error, context) {

            // probably timed out. set now as creation date
            // attach the error
            context.creation_date = new Date();
            context.error = error.message;
            // still need to decrement count so we don't get stuck
            checkCount();
        }, 10000, site);
        // we want to give a reasonable timeout value because
        // we are doing a bunch of stuff here. it should not 
        // take this long, just being safe

    };
});
票数 2
EN

Stack Apps用户

发布于 2010-07-24 19:54:56

试试这个:

  1. 分离元站点(使用linked_meta状态)
  2. 按年龄排序
  3. 将StackApps移到底部(作为特例)
  4. 重新插入其链接站点下面的元站点(按地址确定)

当然,您应该积极地缓存它。特别是,可以无限期地缓存站点时间,这将在每个recalc上保存您的#(站点)请求。

票数 1
EN

Stack Apps用户

发布于 2010-07-24 20:15:08

好吧,下面是StackMobile所发生的事情:

  1. 检索站点列表并将其存储在以站点名称作为键的关联数组中。
  2. 通过枚举数组创建了一个新列表:
    • 如果该项目的类型为“linked_meta”,则查看是否存在同名的另一个站点。
      • 如果是,将其添加到该站点。(其母公司)
      • 如果没有,则添加一个单独的条目。

代码语言:javascript
复制
- If not, just add it to the list.
  1. 三部曲网站被从名单中删除。(此方法的唯一硬编码部分!)
  2. 剩下的项目是页面上的echod。

注意:这并不完全正确,因为StackMobile将StackAuth数据缓存在数据库中。但为了简单起见,假装没有。

票数 0
EN
页面原文内容由Stack Apps提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackapps.com/questions/1203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档